这是我第一次开始编写可执行的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}')
# or out2=$(awk '{print $1,$2}' <<<"$out") in bash