我一直在bash脚本中进行模糊重定向。
我是新手,所以如果有人能解释我为什么用以下代码来解决这个问题,那就太棒了。
这是我的代码!
$input = [user inputs an email]
$variable=$(date +"%Y-%m-%d-%H:%M")
$mem_list=/root/Desktop/Dan/Logs/member-name-file" "$variable.txt
这里的代码变得含糊不清(其中有几个,但同样的问题。
if [[ -f $mem_list ]] #check if file exists already
then
echo $input >> $mem_list #if file is already there, just append input to the file
else
echo $input > $mem_list #if file is not found, make a new one [Error is here!!]
fi
请帮助我,谢谢!
答案 0 :(得分:3)
因为$ mem_list包含空格,所以你必须引用它; e.g。
if [[ -f "$mem_list" ]]
echo $input >> "$mem_list"
答案 1 :(得分:0)
您的变量分配也是错误的。左值没有$
符号,=
周围不能有空格。
mem_list="/root/Desktop/Dan/Logs/member-name-file $variable.txt"
[user inputs an email]
你是什么意思?我的bash 4.2有点困惑......