`
BonnieTang
  • 浏览: 2308 次
  • 性别: Icon_minigender_2
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Bash special variable:$#, $$, $@, $*, $0, $?

    博客分类:
  • Unix
阅读更多
special variable:$#, $$, $@, $*, $0, $?

1, $#
The number of arguments supplied to a script.
eg:
if [ "$#" -eq 0 ]; then
  echo "you did not pass any parameter"
fi

echo "Total Number of Parameters : $#"
Total Number of Parameters : 2

2, $$
The process number of the current shell. For shell scripts, this is the process ID under which they are executing.

3, $@
the "$@" special parameter takes the entire list and separates it into separate arguments.
All the arguments are individually double quoted. If a script receives two arguments, $@ is equivalent to $1 $2.

4, $*
the "$*" special parameter takes the entire list as one argument with spaces between.
All the arguments are double quoted. If a script receives two arguments, $* is equivalent to $1 $2.

5, $0
The filename of the current script.

6, $?
represents the exit status of the previous command.
0 if they were successful, and 1 if they were unsuccessful.
eg:
touch test.ksh
write in test.ksh as below:
-----------------------
#create a stored procedure, name do_feed_processing.
do_feed_processing() {
  ....
  return 0
}
#execute do_feed_processing
do_feed_processing
#print execution result
echo $?
-----------------------
$ sh test.ksh
$ 0
分享到:
评论

相关推荐

    解决ssh远程登陆linux显示-bash-4.1$的问题

    cp -pr /etc/skel/.bash* /home/test/ #/home/test是用户目录 改变用户家目录:usermod -md /tmptest test 以上就是小编为大家带来的解决ssh远程登陆linux显示-bash-4.1$的问题全部内容了,希望大家多多支持软件开发...

    shell脚本实现磁盘监控系统

    /bin/bash #Author:GaoHongYu #QQ:1061767621 #Time:2019-12-24 18:43:22 #Name:ncjk.sh #Version:V1.0 clear xtip=$(hostname -I) cprl=$(df -Th |head -2|tail -1|cut -d -f 10) cpky=$(df -Th |head -2|tail -1|...

    docker容器中 bash: vi: command not found,docker apt-get 异常 Temporary failure resolving

    bash: vi: command not found, 场景: 因为 docker里面没有这个命令,我们安装一下 apt-get update apt-get install vim 如果 这个时候 安装也还是会出现 异常 root@446d7cf1606c:/etc/mysql# apt-get update ...

    bash-module:Bash的模块系统

    Bash模块系统 这是一个概念,表明在Bash中使用完全隔离脚本的模块化系统是可能的。 要对其进行测试,请从项目目录运行: bash test/test.sh 基本用法 #! /bin/bash cd $( dirname ${0} ) # # Initialize module ...

    go-bash-wrapper:使用Golang运行bash脚本

    使用Golang运行bash脚本 安装 高朗 $ go get -u github.com/clarketm/go-bash-wrapper 用法 # Basic usage $ go-bash-wrapper ~ /path/to/script # Forward command line arguments $ go-bash-wrapper ~ /path/to/...

    jdk1.8.0_231

    配置环境变量,vi /etc/profile,在文件最后添加配置 JAVA_HOME=/usr/local/java/jdk1.8.0_231/ JRE_HOME=/usr/local/java/jdk1.8.0_231/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_...

    修复bash漏洞的bash-4.4.tar.gz源码包

    linux 服务器GNU Bash小于版本4.3有操作系统命令注入漏洞,需要对bash升级,下载解压 #tar zxvf bash-4.4.tar.gz #cd bash-4.4 #./configure (如果centos7编译失败,请先安装#yum install gcc) #make #make ...

    破壳漏洞(shellshock)RHEL 4(32位)补丁

    [root@localhost ~]# rpm -Uvh --force bash-3.0-27.0.2.el4.i386.rpm warning: bash-3.0-27.0.2.el4.i386.rpm: V3 DSA signature: NOKEY, key ID b38a8516 Preparing... ########################################...

    shell脚本执行jps时:-bash: jps: command not found

    /bin/bash #查看每个节点运行情况 for((host=101;host<108;host++));do echo -----------hadoop$host------------- ssh hadoop$host jps done 这里默认服务器节点的名字是hadoop101-hadoop107 默认已经配置了...

    02-SHELL编程之流程控制和循环语句

    -eq 0 ];then echo "当前主机和远程主机$IP是互通的。" else echo "当前主机和远程主机$IP是不通的。" fi 或者 #!/bin/bash # Name:ping.sh # Path:/shell02/ # Usage:/shell02/ping.sh # ... #使用ping命令来...

    rvm-1.29.11.tar.gz

    $ \curl -L https://get.rvm.io | bash -s stable 它会自动创建一个“ $HOME/.rvm ”文件夹,这是 RVM 的工作目录。在此文件夹中,有三个文件夹: scripts 、environments 和 srcs 。 接下来,就输入以下命令,安装...

    mva

    一些有用的bash命令: $ # Create a new environment$ mkvirtualenv [-a DIR] env_name$$ # Use the environment (and jump to directory DIR if provided)$ workon env_name$$ # Create a kernel that uses this ...

    Linux if语句详解

    /bin/bash # This script prints a message about your weight if you give it your # weight in kilos and hight in centimeters. if [ ! $# == 2 ]; then echo "Usage: $0 weight_in_kilos length_in_centimeters...

    Shell脚本实现上传zip压缩文件到FTP服务器

    # /bin/bash # creator:lihuibin # date : 2014-03-10 16:45 # desc : upload file to ftp hosts=”192.168.56.100″ port=21 user=test pass=testpwd work_path=”/var/www/cms” packname=”publish” #hosts=$1 #...

    bash脚本指南:高级Bash脚本指南(基于花粉的新版本)

    自述文件高级Bash脚本指南(基于花粉的新版本) HTML中的高级Bash脚本指南: 主页: 关于《高级Bash脚本指南》是由Mendel Cooper撰写的书,并且是《 Linux文档项目》(页面)“。 这是自2014年以来致力于公共领域的...

    Bash脚本内置的调试方法技巧

    用 Bash 写的脚本也可以进行调试,和 Python,Perl 等解释型语言一样。新建一个名为 servinfo 的脚本并增加可执行权限: 代码如下: $ vi servinfo #!/bin/bash echo “Hostname: $(hostname)” echo “Date: $(date...

    Mac版本cmdline-tools工具包

    32.0.0" "platforms;android-32" "platform-tools"`, #加~/.bash_profile ANDROID_HOME="/Users/uuu/Library/Android/sdk" export ANDROID_HOME # Setting PATH for ANDROID_HOME # PATH="$ANDROID_HOME/cmdline-...

    Shell中整数计算的几种方式

    在Shell中可以使用下列方式来做整数的计算(+,-,*,/) 方式一: linux:~ # A=1 linux:~ # B=2 linux:~ # C=$(($A+$B)) linux:~ # echo $C 3 方式二: linux:~ # A=1 linux:~ # B=2 linux:~ # C=$[$A + $B...linux:~ # B=2

    bash-scripts:样例bash脚本

    bash脚本用法 首先,您需要找出您的bash解释器在哪里。 在命令行中输入以下内容: which bash 注意:本教程中的每个bash shell脚本均以shebang开头:“#!” 不作为注释阅读。 第一行也是放置解释器的地方,在...

    linux下提示bash-command not found.docx

    linux下提示bash-command not found.docx

Global site tag (gtag.js) - Google Analytics