我創建了一個腳本,它創建兩個文件,並在兩個文件不同時反轉其內容。我無法理解如何解決這個錯誤:[:<filename>:shell編程中的意外錯誤
[:我的文件名:意外的錯誤在shell編程
代碼:
echo "Enter first filename :"
read file1
echo "Enter second filename:"
read file2
echo "Enter content of file 1 : "
gedit $file1
echo "Enter content of file 2 : "
gedit $file2
check=" "
x=` cmp $file1 $file2 `
if [ $x -eq $check ]
then
echo "Both files are same"
rm $file2
echo "Redundant file removed!!!"
else
echo "They are different"
fi
tac $file1 | cat > temp1
rev temp1 | cat > temp11
tac $file2 | cat > temp2
rev temp2 | cat > temp22
mv temp11 $file1
mv temp22 $file2
echo "Content of both the files reversed"
哪行代碼導致錯誤? – 2013-04-11 17:47:48
我的猜測是這樣的:'if [$ x -eq $ check]'應該可以重寫爲if'「$ x」==「$ check」]'作爲開始。 – William 2013-04-11 18:05:16
當提出這樣的問題時,您需要發佈顯示問題的最小代碼片段。這意味着(因爲你的問題幾乎肯定存在於你的'if'中)跳過所有「輸入內容」的東西,以及'tac'的東西(不管那是什麼)。你應該能夠產生一個四行或五行的例子,它能夠再現出現問題的地方。回報(除了讓人們更有可能幫助你),你通常會通過這條路線發現自己的解決方案。 – 2013-04-11 18:26:24