Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在linux中使用文件作为参数运行脚本_Linux_Bash_Unix_Parameters_Scripting - Fatal编程技术网

在linux中使用文件作为参数运行脚本

在linux中使用文件作为参数运行脚本,linux,bash,unix,parameters,scripting,Linux,Bash,Unix,Parameters,Scripting,我寻找这个答案已经有一段时间了,但并没有得到正确的例子或答案,在linux中,如何使用文件作为参数运行脚本我想提出一些建议,如果用户在bash中键入:#/script.sh check1.txt,那么它如何自动显示文件内容或进行适当的脚本处理。我不确定我的解释是对还是错,但这是我能做的最好的解释。给我任何建议,例子或链接。干杯。这很简单,您的脚本需要使用如下命令行参数 # script.sh looks e.g. like this infile=$1 second_param=$2 cat

我寻找这个答案已经有一段时间了,但并没有得到正确的例子或答案,在linux中,如何使用文件作为参数运行脚本我想提出一些建议,如果用户在bash中键入:
#/script.sh check1.txt
,那么它如何自动显示文件内容或进行适当的脚本处理。我不确定我的解释是对还是错,但这是我能做的最好的解释。给我任何建议,例子或链接。干杯。

这很简单,您的脚本需要使用如下命令行参数

# script.sh looks e.g. like this

infile=$1
second_param=$2

cat $infile > /tmp/$second_param
或者你喜欢的任何东西。然后你像你期望的那样称呼它:

./script.sh check1.txt

如果需要第二个参数

./script.sh check1.txt 123