당신은 변수를 인용 할 필요가있다. bash가 $ a를 확장 할 때 공백은 인수로 표시되지 않으므로 echo로 인쇄되지 않습니다.
명령에는 많은 공백이있을 수 있지만 bash는 기본적으로 명령과 인수를 구분하기 위해 공백을 사용하기 때문에 명시 적으로 인수의 일부 (따옴표 또는 이스케이프 사용)가 아니면 여분의 공백이 무시됩니다.
예를 들어
:
=> touch file 1 # Makes two files: "file" and "1"
=> touch "file 1" # Makes one file: "file 1"
=> touch file\ 1 # Makes one file: "file 1"
귀하의 최종 코드는 다음과 같습니다 :
while read line
do
a=`echo $line | cut -c 2`
b=`echo $line | cut -c 7`
echo -n "$a"
echo "$b"
done
그들이 인용되지 않는 공간, 파일 이름에서 탈출해야하는 이유
=> echo a # Argument without spaces works (at least in this case)
a
=> echo a # Two spaces between, unquoted spaces are ignored
a
=> echo " a" # Quotes make the space part of the argument
a
=> echo a # Arguments can have many spaces between them
a
=> echo # No quotes or spaces, echo sees no arguments, doesn't print anything
=> echo " " # Space is printed (changed to an underscore, wouldn't actually be visible)
_
=>
이 또한