2

There is a quite nasty expression that want to echo using bash.

The expression is:

'one two -- 

Note: There is white space after --.

So I have:

IFS=
echo 'one$IFStwoIFS--$IFS

But the result is:

one$IFStwo$IFS--$IFS
3
  • You have a typo - it is IFS, not ISF. Also, you don't have the completing single quote. Commented Jun 2, 2018 at 13:52
  • 2
    See: Difference between single and double quotes in Bash. Commented Jun 2, 2018 at 13:54
  • @codeforester just a mistake Commented Jun 3, 2018 at 10:56

1 Answer 1

3

You have few issues with your approach:

  1. Within single quote variables are not expanded in shell
  2. In the string one$IFStwo$IFS--$IFS first instance of $IFS will not be expanded since you have string two next to $IFS so it attempts to expand non-existent variable $IFStwo.
  3. Default value of $IFS is $' \t\n'

You can use:

echo "one${IFS}two$IFS--$IFS"

which will expand to (cat -A output):

one ^I$
two ^I$
-- ^I$
Sign up to request clarification or add additional context in comments.

8 Comments

Try this: ( IFS=' ' && echo "<one${IFS}two$IFS--$IFS>"; )
good... this worked: IFS=' ';echo$IFS"'or${IFS}true$IFS--$IFS". pardon. If i replace something else with IFS=' ' . I mean I want to replace something else with whitespace in IFS=' '. What should I do/
Didn't get but ( IFS=':'; echo "<one${IFS}two$IFS--$IFS>"; ) also works fine.
I need a character else instead of whitespace but working as whitespace... when I run bash I need to hide whitespace
Really thank you for supporting me. I mean what special character I can use in IFS=' ' instead of whitespace?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.