The set command sets the parameter variables for the shell. The output of many commands is a space-delimited value, and using set is very effective if you want to use one of these data fields.
#!/bin/sh
echo the date is $ (date)
Set $ (date)
echo the month is $
Output:
The date is Wed Apr 15:34:16 CST 2014
The month is APR
The output of the date command is set to the parameter table, and the month is obtained by the position parameter. Because the date command is greatly influenced by language and geography, if the purpose is to remove the name of the month, you should use date +%b.
You can also use the SET command to control how the shell executes. The most common of these is set +x, which enables the script to trace the currently executing command.
Let's look at the following example:
[Email protected] shell]# ls/opt
File file3 haha Mimei
[[Email protected] shell]# set--$ (ls/opt)
[Email protected] shell]# echo $
File
[Email protected] shell]# Echo
File3
[[email protected] shell]# echo $
haha
[Email protected] shell]# echo $4
Mimei
[Email protected] shell]# echo $#
4
[Email protected] shell]# echo [email protected]
File file3 haha Mimei
[Email protected] shell]#
Set in the Shell--usage