Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
more or less:
echo -e alan{1..3}"\013\015"
why do you need that?
hi pan64, nothing much, testing brace expansion while reading "Bash Guide For Beginner" here and there and encounter this phrase below
Quote:
3.3.4. Double quotes
Using double quotes the literal value of all characters enclosed is preserved, except for the dollar sign, the
backticks (backward single quotes, ``) and the backslash.
The dollar sign and the backticks retain their special meaning within the double quotes.
The backslash retains its meaning only when followed by dollar, backtick, double quote, backslash or newline. Within double quotes, the backslashes are removed from the input stream when followed by one of
these characters. Backslashes preceding characters that don't have a special meaning are left unmodified for
processing by the shell interpreter.
I am trying to simulate how newline works with backslash in double quotes but cant understand how to simulate a newline.
Code:
[root@racnode1 ~]# echo "ok now \\ is working as required, showing the \\"
ok now \ is working as required, showing the \
[root@racnode1 ~]# echo "ok now \\ is working as required, showing \$(date) as \$(date)"
ok now \ is working as required, showing $(date) as $(date)
[root@racnode1 ~]#
[root@racnode1 ~]# echo "ok now \\ is working as required, showing newline as \\n instead"
ok now \ is working as required, showing newline as \n instead
All is okay until i add a "-e"
Code:
[root@racnode1 ~]# echo -e "ok now \\ is working as required, showing newline as \\n instead"
ok now \ is working as required, showing newline as
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" ...
\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).
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.