BASH: Strip new-line character from string (read line)
问题 I bumped into the following problem: I'm writing a Linux bash script which does the following: Read line from file Strip the \n character from the end of the line just read Execute the command that's in there Example: commands.txt ls ls -l ls -ltra ps as The execution of the bash file should get the first line, and execute it, but while the \n present, the shell just outputs "command not found: ls" That part of the script looks like this read line if [ -n "$line" ]; then #if not empty line