Example of positional variable parameters (special characters) in shell script _linux shell

Source: Internet
Author: User

$#: Number of parameters passed to script
$*: Displays all parameters passed to the script in a single string. Unlike positional variables, this option argument can exceed 9
$$: The current process ID number of the script run
$! : The process ID number of the last process running in the background
$@: With $ #相同, but with quotes and returns each argument in quotation marks
$-: Displays the current options used by the shell, the same as the SET command
$? : Displays the exit status of the last command. 0 indicates no errors, and any other value indicates an error.

Copy Code code as follows:

#!/bin/sh
#param. Sh

# $: File Full path name
echo "Path of script: $"
# Get file name using basename command file path
echo "Name of script: $ (basename $)"
# $1: Parameter
echo "Parameter 1: $"
# $: Parameter 2
echo "Parameter 2: $"
# $: Parameter 3
echo "Parameter 3: $"
# $: Parameter 4
echo "Parameter 4: $"
# $: Parameter 5
echo "parameter 5: $"
# $#: Number of parameters passed to script
echo "The number of arguments passed: $#"
# $*: Show all parameter Contents I
echo "Show all arguments: $*"
# $: ID number of the script currently running
echo "Process ID: $"
# $?: Return code
echo "Errors: $?"

Enter./param.sh Hello World

Copy Code code as follows:

[Firefox@fire shell]$./param.sh Hello World
Path of script:./param.sh
Name of script:param.sh
Parameter 1:hello
Parameter 2:world
Parameter 3:
Parameter 4:
Parameter 5:
The number of arguments Passed:2
Show All Arguments:hello World
Process id:5181
errors:0

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.