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

问题描述 投票:0回答:1

这是我第一次开始编写可执行的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

bash shell terminal executable
1个回答
0
投票

请您使用上面编写的脚本编写一个保存中间变量的示例命令

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
© www.soinside.com 2019 - 2024. All rights reserved.