Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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_Shell_Terminal_Executable - Fatal编程技术网

将中间文件另存为bash脚本中的变量

将中间文件另存为bash脚本中的变量,bash,shell,terminal,executable,Bash,Shell,Terminal,Executable,这是我第一次开始编写可执行的bash脚本。 我有四个命令行,我想放在一个.sh文件中,然后在一个csv文件上运行。 我想避免使用一行很长的命令,例如,command1 | command2 | command3 | command4,相反,我需要将中间输出保存在临时变量中,或者使用一些东西代替管道 我尝试了这个,但没有给出正确的输出: filename="$2" outputname="$3" if [[ $1 = "-u" ]]; then out= cut -f1,3,7,8

这是我第一次开始编写可执行的bash脚本。 我有四个命令行,我想放在一个.sh文件中,然后在一个csv文件上运行。 我想避免使用一行很长的命令,例如,
command1 | command2 | command3 | command4
,相反,我需要将中间输出保存在临时变量中,或者使用一些东西代替管道

我尝试了这个,但没有给出正确的输出:

filename="$2"
outputname="$3"

if  [[ $1 = "-u" ]]; then
    out= cut -f1,3,7,8  "${filename}" | grep "*_11_0" | tr , ':'
    out2= awk '{print $1,$2}' "${out}"
    echo "${out}"

else
    echo "Error: You have to specify an option"
fi

你能用我上面写的脚本做一个保存中间变量的示例命令吗

out=$(cut-f1,3,7,8“$filename”| grep“*_11_0”| tr,:”)
out2=$(printf“%s\n”$out“| awk'{print$1,$2}')

#或out2=$(awk'{print$1,$2}“
我想避免一行很长的命令
为什么?你可以在
|
后面加上换行符,或者加上\反斜杠并打断换行符。你对这个主题做过任何研究吗?我建议你给我一个很好的提示。你能用我上面写的脚本做一个保存中间变量的示例命令吗对我来说,你不需要引用没有空格、全局字符等的常量字符串;您确实需要引用参数展开式。
out=$(cut -f1,3,7,8  "$filename" | grep "*_11_0" | tr , ':')
out2=$(printf "%s\n" "$out" | awk '{print $1,$2}')
# or out2=$(awk '{print $1,$2}' <<<"$out") in bash