[SOLVED] Wrapping a long command with \ on the CLI isn't working
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.
Wrapping a long command with \ on the CLI isn't working
So I'm running a very long command from the CLI. I've tried to use the \ to tell the prompt that there are more commands coming or will be on the next line, however the prompt goes to > and I can't enter those commands anymore.
This is the command that I'm trying to enter all on one line:
to break up a command in order for this to work, correct?
yes that silly \ <-- thing is called the backslash when ever you read something that tells you you have to use an escape that is what they are talking about \
Code:
printf "I want to add a new line!\n"
the \ escapes the n from being read as part of the prefix, then reads it as a command instead. n meaning newline in C and other programming Langs.
when using the command line or in BASH Script even, and some programming langs one can use the \ when they do not want to write it out in one LONG line - which by the way it is being read by the compiler or interpreter as one long line.
For the writers benifit to be able to read it eaiser they developed the system to accept an \ to tell the compiler or interpreter to see the users "new line" as one steady line without that end line char it put there when one hits the return/enter button. it escapes that char that is put there that you cannot see and keeps it reading the rest of the command line as if it is just one steady line of text/code... etc
and like @Habitual said, you have to put it in the right spot of the command or it will misinterpret it
and like @Habitual said, you have to put it in the right spot of the command or it will misinterpret it
someone correct me if I am wrong.
You can break the line just about anywhere except within a single-quoted string. The "" character does have to immediately precede the newline, and you do have to avoid the mistake of omitting needed whitespace between command arguments.
Code:
$ echo These are separate\
> words
These are separatewords
$ echo These are separate \
> words
These are separate words
So I've scripted up this long command line and it errors out. I've even used the back-slash and still getting an error on the next command where the line breaks:
Code:
[root@server scripts]# ./satellite_channel_sync_rhel6.sh
15:03:07 Red Hat Satellite - file-system synchronization
15:03:07 mp: /tmp/satdump
15:03:07
15:03:07
15:03:07 Retrieving / parsing channel-families data
15:03:07 channel-families data complete
15:03:07
15:03:07 Retrieving / parsing product names data
15:03:07
15:03:07 Retrieving / parsing arches data
15:03:08 arches data complete
15:03:08
15:03:08 Retrieving / parsing additional arches data
15:03:08 additional arches data complete
15:03:08
15:03:08 Retrieving / parsing channel data
15:03:08 ERROR: these channels either do not exist or are not available:
15:03:08
15:03:08 (to see a list of channel labels: /usr/bin/satellite-sync --list-channels)
./satellite_channel_sync_rhel6.sh: line 5: rhel-x86_64-server-supplementary-6: command not found
So I've scripted up this long command line and it errors out. I've even used the back-slash and still getting an error on the next command where the line breaks:
15:03:08 Retrieving / parsing channel data <-- when it calls this one it does not (keep reading)
15:03:08 ERROR: these channels either do not exist or are not available:
15:03:08
15:03:08 (to see a list of channel labels: /usr/bin/satellite-sync --list-channels)
./satellite_channel_sync_rhel6.sh: line 5:rhel-x86_64-server-supplementary-6: command not found
bold is the problem and underline means you do not have that installed or it is not actually an option / valid command
line five that calls that function is bad.
rhel-x86_64-server-supplementary-6:
you have to find correct channel
Use the rhn-channel --list command to confirm the list of channels to which the server is subscribed.
was that a backwards statment? because your script when broken up didn't work.
so I'll take it that it was and say, if it was me (keeping in mind I don't use red hat so I can't do this in order to figure it out).
I got two options. I'd take the one that works.
If I was putting it into a bash script. then I'd run it all on one line, or I could fiddle with it until I find the break points within the long line until that works.
was that a backwards statment? because your script when broken up didn't work.
so I'll take it that it was and say, if it was me (keeping in mind I don't use red hat so I can't do this in order to figure it out).
I got two options. I'd take the one that works.
If I was putting it into a bash script. then I'd run it all on one line, or I could fiddle with it until I find the break points within the long line until that works.
[root@server scripts]# ./satellite_channel_sync_rhel6.sh
13:03:49 Red Hat Satellite - file-system synchronization
13:03:49 mp: /tmp/satdump
13:03:49
13:03:49
13:03:49 Retrieving / parsing channel-families data
13:03:49 channel-families data complete
13:03:49
13:03:49 Retrieving / parsing product names data
13:03:50
13:03:50 Retrieving / parsing arches data
13:03:50 arches data complete
13:03:50
13:03:50 Retrieving / parsing additional arches data
13:03:50 additional arches data complete
13:03:50
13:03:50 Retrieving / parsing channel data
13:03:51 ERROR: these channels either do not exist or are not available:
13:03:51
13:03:51 (to see a list of channel labels: /usr/bin/satellite-sync --list-channels)
./satellite_channel_sync_rhel6.sh: line 11: rhel-x86_64-server-ha-6: command not found
./satellite_channel_sync_rhel6.sh: line 14: rhel-x86_64-server-supplementary-6: command not found
./satellite_channel_sync_rhel6.sh: line 15: rhn-tools-rhel-x86_64-server-6: command not found
[root@server scripts]#
I think you will find that several of those lines have white space following the backslash character. In order to ignore the newline and merge the lines, the newline must immediately follow the backslash.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.