【问题标题】:meaning of $@ in unix shell script [duplicate]unix shell脚本中$@的含义[重复]
【发布时间】:2017-08-11 15:06:41
【问题描述】:

这是我的一段代码:

##Checking swapspace if ignore option chosen will force creation of swap space
echo ; echo "[INFO]: Validating Swap space "
swapspace=`swapon -s|tail -1|awk '{print $3/1024}'`
if [ ${swapspace} -le 500 ]; then
        echo $@ |grep ignore>/dev/null
         if [ `echo $?` -eq 0 ]; then
         echo "[WARNING]: Swap space is below minimum requirement get the same fixed :${swapspace}
            Proceeding with WorkAround. PLEASE GET IT FIXED AT THE EARLIEST"

                dd if=/dev/zero of=/swapfile bs=2G  count=4
                chmod 0600 /swapfile; mkswap /swapfile; swapon /swapfile
                export SWAPFLAG=1

        else
         echo "[ERROR]: Swap space is below minimum requirement get the same fixed :${swapspace}"
          export SWAPFLAG=2
        fi


fi

谁能解释一下 echo $@ 在这里做什么?

PS: 'ignore 是一个隐藏的参数'

【问题讨论】:

  • Surbhi:请不要在您的帖子/问题中提及大写字母。您应该提供问题的完整详细信息以及预期的输出,以便更好地指导您的问题,我希望这会有所帮助。

标签: unix


【解决方案1】:

@苏比: $@ 表示传递给脚本的所有参数。例如--> ./test.ksh test1 test2 然后$@ 将等于test1 test2

【讨论】:

    【解决方案2】:

    如果您运行带有参数的 shell 脚本,例如:

    ./myscript goodbye cruel world
    

    您可以在脚本中访问这些参数。特别是$@ 会在输入时为您提供所有内容 - 例如如果myscript.sh

    #! /bin/sh
    echo $@
    

    上面的命令只是将goodbye cruel world打印到终端

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 2012-09-09
      • 2016-07-12
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多