如何在shell/bash脚本中更改argv [0]的值? [英] How to change argv[0] value in shell / bash script?
本文介绍了如何在shell/bash脚本中更改argv [0]的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
set
命令可用于更改位置参数$ 1 $ 2的值...
The set
command can be used to change values of the positional arguments $1 $2 ...
但是,有什么方法可以更改$ 0吗?
But, is there any way to change $0 ?
推荐答案
#! /bin/sh
# try executing this script with several arguments to see the effect
test ".$INNERCALL" = .YES || {
export INNERCALL=YES
# this method works both for shell and bash interpreters
sh -c ". '$0'" argv0new "$@"
exit $?
}
printf "argv[0]=$0\n"
i=1 ; for arg in "$@" ; do printf "argv[$i]=$arg\n" ; i=`expr $i + 1` ; done
这篇关于如何在shell/bash脚本中更改argv [0]的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文