我正在嘗試將 bash 命令的結果存盤在 for 回圈中以在命令中使用。這是我目前擁有的:
for filename in /home/WIN/USER/files/*
var=$(basename ${filename%.*}) | awk -F'[_.]' '{print $1}'
do echo var
done
但是,我收到這些錯誤:
./script.sh: line 2: syntax error near unexpected token `var=$(basename ${filename%.*})'
./script.sh: line 2: `var=$(basename ${filename%.*}) | awk -F'[_.]' '{print $1}''
有誰知道如何解決這個問題或如何做我想做的事情?
謝謝。
uj5u.com熱心網友回復:
你的for陳述句是錯誤的,你的變數賦值陳述句也是錯誤的。你應該這樣寫:
for filename in /home/WIN/USER/files/*; do
var=$( your shell code goes here ) # you assign the output of the shell code here
echo $var # you echo the results here
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/462386.html
