암호:-
filesDirName="/C/Users/OM\\ SAI\\ RAM/HelloWorldSagar"
echo ${filesDirName}
echo "cd ${filesDirName}"
cd ${filesDirName}
배시 출력:-
$ ./files.sh
/C/Users/OM\ SAI\ RAM/HelloWorldSagar
cd /C/Users/OM\ SAI\ RAM/HelloWorldSagar
./files.sh: line 4: cd: too many arguments
답변1
이와 같이:
# No backslash before space needed, as the entire sting is quoted with "
filesDirName="/C/Users/OM SAI RAM/HelloWorldSagar"
# echo allows multiple parameter, so it worked by chance
# You should quote it anyway
echo "${filesDirName}"
echo "cd ${filesDirName}"
# quote the parameter
cd "${filesDirName}"
경험 법칙: 의심스러운 경우 변수를 인용하십시오.
참고: 코드를 4칸 들여쓰기하여 코드 블록으로 표시합니다.