I've written before. A problem was encountered when naming filenames automatically by date and time.
#! /bin/"Pleaseinput the filename:" filenamedate3'2 days ago ' +%y%m%/home//home/$filename'_'/ home/"$filename _$date3"
Output is three files
23:22 20130329
23:22 underline_20130329
23:22 underline_20130329
Isn't it supposed to be the same for all three, all in the form of a filename_date,
And then I switched to a dash,
#! /bin/"Pleaseinput the filename:" filenamedate3'2 days ago ' +%y%m%/home/${filename}-/home/$filename'-" /home/"$filename-$date 3"
The output files are:
23:24 dash-20130329
23:24 dash-20130329
23:24 dash-20130329
If the auto-named file delimiter is not a problem with a dash, why is it so?
Later through study and study
The shell variable name is followed by a non-lowercase string (including the size string), a number or an underscore, or the escape character "\" or the variable name with curly braces. Otherwise, the shell in this case attempts to use filename_ as the variable name. The statement does not print anything (null or an empty string) unless there is an accidental case where $filename_ already exists, which is why the file 20130329 was output for the first time.
In the shell, the method of taking a variable value $varname syntax is actually a shorthand form of common syntax ${varname}, whether it is to avoid ambiguity, or to increase readability, the variable plus parentheses are a good habit, do not lazy not to add yo.
P.S. Examples of Simplicity
[[email protected] mybash]#A=a[[email protected] mybash]#b=b[[email protected] mybash]#Echo $a $bAb[root@Linux Mybash]# Echo $a _$bB[root@Linux Mybash]#Echo $a \_$bA_b[root@Linux Mybash]#Echo ${a}_${b} #推荐方法A_b[root@Linux Mybash]#echo "$a" _ "$b"A_b[root@Linux Mybash]#echo $a "_" $bA_b
The small symbol reflects the big problem, the shell underline _ and the variable relationship.