Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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
bash脚本外部输入文件的设置_Bash - Fatal编程技术网

bash脚本外部输入文件的设置

bash脚本外部输入文件的设置,bash,Bash,我处理的是bash脚本,它对一组文件执行一系列操作,每个文件都使用for循环加载到脚本中 # run script.sh script=./ for pdb in ${script}/workdir/*.pdb; do #some operations done 是否有可能通过shell提供给脚本文件的一些标志来定义workdir,其中所有输入pdb文件都位于脚本之外 # run script.sh -r <path_to_the_work_dir> 我想应该对for循环的

我处理的是bash脚本,它对一组文件执行一系列操作,每个文件都使用for循环加载到脚本中

# run script.sh
script=./
for pdb in ${script}/workdir/*.pdb; do
   #some operations
done
是否有可能通过shell提供给脚本文件的一些标志来定义workdir,其中所有输入pdb文件都位于脚本之外

# run script.sh -r <path_to_the_work_dir>
我想应该对for循环的脚本主体进行哪些修改? 将脚本外部的一些变量移动到Bash中script.sh文件提供的一些标志的一般方法是什么

谢谢你的帮助


James

在函数中调用workdir=$1之前定义它。如果需要更多变量,则连续定义它们:var2=$2,var3=$3

当从外部调用函数时,只需给出路径

# run script.sh
workdir=$1
script=./
for pdb in ${script}/${workdir}/*.pdb; do
   #some operations
done
电话: 一个您想要的变量:

script.sh /home/lalal/functions/lalsl/
如果需要,附加变量:

script.sh /home/lalal/functions/lalsl/ var2 var3

您可以将参数传递给脚本。这些参数可用作位置参数$1、$2等。你可以用它们做任何你想做的事情。@James Starlight如果答案对你有用,请在左边接受它