brace expansion + new line
Hi all,
How do i make Code:
[alan@racnode1 scripts]$ echo alan{1..3} Quote:
Tried -e + /n to no avail. Code:
[alan@racnode1 scripts]$ echo alan{1..3}\n Regards, Noob |
Messy but:
Code:
echo alan{1..3}|sed 's/ /\n/g' Code:
for x in (1..3); do echo alan$x;done |
more or less:
echo -e alan{1..3}"\013\015" why do you need that? |
Quote:
|
Quote:
Quote:
Code:
[root@racnode1 ~]# echo "ok now \\ is working as required, showing the \\" Code:
[root@racnode1 ~]# echo -e "ok now \\ is working as required, showing newline as \\n instead" Why isn't "\" working as it suppose to be when i add a "-e" , the 1st "\" is suppose to remove any special meaning from the subsequent character which is "\n" ... Regards, Noob |
try the following instead:
Code:
$ printf "%s\n" alan{1..3} |
\013 and \015 are octal chars and evaluated for me, but the solution of jpollard looks much better.
So regarding evaluation: it is really hard, or better to say complex. First always the current shell will try to interpret the string you entered. Next, the command will try to use (and do what it want) the command line parameters passed by the shell. In your case the question is: who will evaluate the \ and { } ? echo -e is able to do interpret \<something> (see man page of bash again), but { } are always evaluated by the shell. Using 'some string' will disable the shell evaluation, but using "some string" will enable that, therefore the shell will also try to "understand" those \ chars (that was what you posted). |
Quote:
|
There is no need for the \013, as that is a carriage return. Putting it there is a DOS thing, and can cause problems depending on how the output is used - for instance, adding a line to a configuration file can cause it to be an illegal character. And that can be rather difficult to see, and the error may not say "illegal character" either (bad format, missing ":", ... or other errors).
|
this is how it was running on ubuntu and on suse:
Code:
user@host:~$ echo -e alan{1..3}"\013\015" |
013 is a vertical tab... 012 is a newline.
Simpler to remember "\n". |
All times are GMT -5. The time now is 07:01 PM. |