0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.