Set in the Shell--usage

Source: Internet
Author: User

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

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.