revposparams.sh

来自「Shall高级编程」· Shell 代码 · 共 66 行

SH
66
字号
#!/bin/bash# revposparams.sh: Reverse positional parameters.# Script by Dan Jacobson, with stylistic revisions by document author.set a\ b c d\ e;#     ^      ^     Spaces escaped #       ^ ^        Spaces not escapedOIFS=$IFS; IFS=:;#              ^   Saving old IFS and setting new one.echountil [ $# -eq 0 ]do          #      Step through positional parameters.  echo "### k0 = "$k""     # Before  k=$1:$k;  #      Append each pos param to loop variable.#     ^  echo "### k = "$k""      # After  echo  shift;doneset $k  #  Set new positional parameters.echo -echo $# #  Count of positional parameters.echo -echofor i   #  Omitting the "in list" sets the variable -- i --        #+ to the positional parameters.do  echo $i  # Display new positional parameters.doneIFS=$OIFS  # Restore IFS.#  Question:#  Is it necessary to set an new IFS, internal field separator,#+ in order for this script to work properly?#  What happens if you don't? Try it.#  And, why use the new IFS -- a colon -- in line 17,#+ to append to the loop variable?#  What is the purpose of this?exit 0$ ./revposparams.sh### k0 = ### k = a b### k0 = a b### k = c a b### k0 = c a b### k = d e c a b-3-d eca b

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?