Special characters in shell Parameters

Source: Internet
Author: User
I have been idle for the past two days, playing Nb, starting with shell, and coming up with something interesting. Remember it by the way.

A simple script test_2 is written to output the user's parameters:
#! /Bin/sh
If [$ #-lt 2]; then
Echo "you need 2 paramerters at less! "
Exit 0
Fi
One = "$1"
Two = "$2"
Echo "Your paramerters are :"
Echo $1
Echo $2

: WQ save;
Chmod + x test_2 make it executable

The execution results of different parameters are as follows:
(1) No parameters:
#./Test_2
You need 2 paramerters at less!

(2)
#./Test_2/43./# $ @&
# Your paramerters are:
/43
./#

---------------------------------------------------------------
No prompt appears. It seems that the command has not been executed.
/*
* It may be because of the special meaning of the last character "&", which is unknown for the moment.
*/
Press enter directly:
[1] Done./test_2/43./# $ {@}

(3)
#./Test_2/43./# $ @
# Your paramerters are:
/43
./#
#

----------------------------------------------------------------
It is the same as the previous output, but a command prompt is displayed, indicating that the command has been executed.

(4)
#./Test_2/43./# $
# Your paramerters are:
/43
./# $
#

----------------------------------------------------------------
It seems to be a normal output. It is normal to remove "@". It is strange.

(5)
#./Test_2/43 ./#
# Your paramerters are:
/43
./#
#

----------------------------------------------------------------
Still normal.
"./Test_2/43./" and "./test_2/43." are normal.

(6)
#./Test_2/43./# $ &
# Your paramerters are:
/43
./# $

-----------------------------------------------------------------
If no prompt is displayed, "./test_2/43./# $" is normal. It seems that this conclusion can be made: "&" can continue execution only after user input. It is not clear what to enter.

(7)
#./Test_2/43./$ @
# Your paramerters are:
/43
./
#
-----------------------------------------------------------------
Compared with case 3, it seems that "$ @" is ignored.

(8)
#./Test_2/43./$4 @
# Your paramerters are:
/43
./@
#
-----------------------------------------------------------------
It's so strange that the headers are all big.

I guess it is normal that shell processes some special characters when passing parameters so that they cannot be directly used as parameters. I probably didn't see the source code and didn't know the rules.

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.