'$ {B-2}' and '$ {B:-2}' in Shell }"

Source: Internet
Author: User
Tags date1

In the shell studyCode

 #  !  /  Bin  /  Bash
# User can keyin filename to touch 3 New Files.
Path = / USR / Local / Sbin: / USR / Local / Bin: / USR / Sbin: / USR / Bin: / Sbin: / Bin: / USR / Games
Export path

Echo " I will use 'touch' command to create 3 files. "
Read - P " Please input the filename what you want: " Fileuser

Filename = $ {Fileuser: + " Filename " }

Date1 = 'Date -- Date = ' 2 days ago ' + % Y % M % D'
Date2 = 'Date -- Date = ' 1 days ago ' + % Y % M % D'
Date3 = 'Date + % Y % M % D'

File1 = " $ Filename "" $ Date1 "
File2 = " $ Filename "" $ Date2 "
File3 = " $ Filename "" $ Date3 "

Touch $ file1
Touch $ file2
Touch $ file3

In
Filename=$ {Fileuser:+"Filename"} For: + is not very clear, and then check the usage.

Lx @ Ubuntu :~ /Bsh/scripts $ B = "" lx @ Ubuntu :~ /Bsh/scripts $ c = "Z" lx @ Ubuntu :~ /Bsh/scripts $ echo a =a {A-1}, B =$ {B-2}, C =$ {C-3} A = 1, B =, c = zlx @ Ubuntu :~ /Bsh/scripts $ echo a =$ {A:-1}, B =$ {B:-2}, C =$ {C:-3} A = 1, B = 2, c = zlx @ Ubuntu :~ /Bsh/scripts $

 
+ Variant + | form meaning + ------------------------------------------------------------------------ + | $ {Variable :? Word} complain if undefined or null | $ {Variable:-word} use new value if undefined or null | $ {Variable: + word} opposite of the above | $ {Variable: = word} use new value if undefined or null, and redefine. + ---------------------------------------------------------------------- +


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.