I have a string like FIRSTNAME\nLASTNAME in a file. I want to put the first name and last name in their own variables. I have to use /bin/sh, not bash.
How can I easily do this?
You can use parameter expansion operators to strip everything following the \n as well as everything preceding it.
$ s="Stealth\nRabbi" $ first=${s%\\n*} $ last=${s#*\\n} $ echo "$first" Stealth $ echo "$last" Rabbi Note that there are no literal newlines involved; you have two characters, \ and n.