Problem with the echo -command in BASH
Hi there, I need something like this:
echo "SOME TEXT `tail -1 `overvieuwFunction` | cut -d" " -f$1` SOME MORE TEXT"; So the next line: tail -1 `overvieuwFunction` | cut -d" " -f$1 I need in an echo. But there are probably to much " and ' Thanks for your help |
Are you looking for this?
Code:
#!/bin/bash Code:
$ ./t.sh |
No, I will explain it like this.
# echo "TEXTA"; RESULT: TEXTA But now I want to have a bash-command (like for instance the whoami bash-command) within the echo: # echo "TEXTB `whoami` TEXTC"; RESULT: TEXTB root TEXTC So these two examples work, but now I want to use a bash-command which needs arguments with f.i. " and ' f.i. the next line I want instead of the whoami bash-command in the example above (the overvieuwFunction is a function I have written, and the tail-command uses the output from this function as its input): tail -1 `overvieuwFunction` |cut -d" " -f1 so I want to really use this line in the echo from above. Thanks and I hope its now clear to you.. |
Does this part work?
Code:
tail -1 `overvieuwFunction` Anyway, the problem you're asking about is that you try to use: `some-command` nested within another set of ` and `. That doesn't work. If you use the bash shell, it can be solved by using $(some-command) syntax. This does the same as the back-tocks (``), but does allow nesting. Code:
echo "TEXTB $(tail -1 $(overvieuwFunction) |cut -d" " -f1) TEXTC"; |
Yes, it has to be:
overvieuwFunction | tail -1 | cut -d" " -f$1 And not: tail -1 `overvieuwFunction` | cut -d" " -f$1 By the way, thanks for the $() solution :-) Greetings from little cold and poor belgium :-) |
Quote:
|
All times are GMT -5. The time now is 12:53 PM. |