如何将BASH变量发送到多个脚本?
我有许多按顺序调用的BASH脚本,例如script1.sh包含:如何将BASH变量发送到多个脚本?,bash,variables,Bash,Variables,我有许多按顺序调用的BASH脚本,例如script1.sh包含: #!/bin/bash bash script2.sh bash script3.sh bash script4.sh #!/bin/bash file_a="1.txt" cp $file_a /tmp/$file_a.tmp #!/bin/bash wc -l /tmp/$file_a.tmp #!/bin/bash cat /tmp/2.txt $file_a.tmp > file3.txt scri
#!/bin/bash
bash script2.sh
bash script3.sh
bash script4.sh
#!/bin/bash
file_a="1.txt"
cp $file_a /tmp/$file_a.tmp
#!/bin/bash
wc -l /tmp/$file_a.tmp
#!/bin/bash
cat /tmp/2.txt $file_a.tmp > file3.txt
script2.sh包含:
#!/bin/bash
bash script2.sh
bash script3.sh
bash script4.sh
#!/bin/bash
file_a="1.txt"
cp $file_a /tmp/$file_a.tmp
#!/bin/bash
wc -l /tmp/$file_a.tmp
#!/bin/bash
cat /tmp/2.txt $file_a.tmp > file3.txt
script3.sh包含:
#!/bin/bash
bash script2.sh
bash script3.sh
bash script4.sh
#!/bin/bash
file_a="1.txt"
cp $file_a /tmp/$file_a.tmp
#!/bin/bash
wc -l /tmp/$file_a.tmp
#!/bin/bash
cat /tmp/2.txt $file_a.tmp > file3.txt
script4.sh包含:
#!/bin/bash
bash script2.sh
bash script3.sh
bash script4.sh
#!/bin/bash
file_a="1.txt"
cp $file_a /tmp/$file_a.tmp
#!/bin/bash
wc -l /tmp/$file_a.tmp
#!/bin/bash
cat /tmp/2.txt $file_a.tmp > file3.txt
每个文件都需要访问一小部分变量。如何将变量从一个脚本传递到下一个脚本?您有很多选择
第一种方法是将变量作为环境变量,并在执行第二个脚本之前传递给脚本
第二种方法是使第二个脚本在同一个shell中运行
通过实例对这些方法进行了很好的描述