對於命令ls
,選項-1
應該運行ls
產生只有一列的輸出(每行產生一個文件)。但是如果我把它放在一個腳本中,它只會顯示一行中卡住的每個文件,並用空格分隔。Ksh ls -1沒有按預期工作
腳本:
#!/bin/ksh
text=`ls -1`
echo $text
文件夾內容:
test
|--bob
|--coolDir
|--file
|--notThisDirectoryAgain
|--script.sh
|--spaces are cool
|--thatFile
腳本輸出:
bob coolDir file notThisDirectoryAgain script.sh spaces are cool thatFile
輸出,如果我在終端(未在腳本中)運行ls -1
bob
coolDir
file
notThisDirectoryAgain
script.sh
spaces are cool
thatFile
嘗試'echo「$ text」'。祝你好運。 – shellter