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. + ---------------------------------------------------------------------- +