LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-04-2016, 03:04 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
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:

Code:
satellite-sync -m /tmp/satdump -c rhel-i386-server-5 -c rhel-i386-server-hts-5 -c rhel-i386-server-productivity-5 -c rhel-i386-server-supplementary-5 -c rhel-i386-server-vt-5 -c rhn-tools-rhel-i386-server-5
The example here is synching downloaded ISOs files with the disconnected Red Hat Satellite.
 
Old 02-04-2016, 03:17 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Depend where you use the \ slash...


Code:
satellite-sync -m /tmp/satdump -c rhel-i386-server-5 -c \ 
rhel-i386-server-hts-5 -c rhel-i386-server-productivity-5 -c \
rhel-i386-server-supplementary-5 -c rhel-i386-server-vt-5 -c \
rhn-tools-rhel-i386-server-5
 
1 members found this post helpful.
Old 02-05-2016, 08:46 AM   #3
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by Habitual View Post
Depend where you use the \ slash...


Code:
satellite-sync -m /tmp/satdump -c rhel-i386-server-5 -c \ 
rhel-i386-server-hts-5 -c rhel-i386-server-productivity-5 -c \
rhel-i386-server-supplementary-5 -c rhel-i386-server-vt-5 -c \
rhn-tools-rhel-i386-server-5
I think I got it. Looks like you have to use the

Code:
\
to break up a command in order for this to work, correct?

Last edited by JockVSJock; 02-05-2016 at 08:50 AM.
 
Old 02-05-2016, 08:57 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by JockVSJock View Post
I think I got it. Looks like you have to use the

Code:
\
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

someone correct me if I am wrong. Thanks

Last edited by BW-userx; 02-05-2016 at 09:23 AM.
 
Old 02-05-2016, 09:59 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by BW-userx View Post
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
 
1 members found this post helpful.
Old 02-05-2016, 10:39 AM   #6
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
The following character was throwing it for me

Code:
>
For some reason, if I get this, it typically means I've fudged something on the CLI. However this is helpful.

thanks
 
Old 02-05-2016, 11:51 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
That's the secondary prompt. You get that when you're in the midst of typing a command line, compound command, or quoted string.
 
Old 02-05-2016, 11:58 AM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by rknichols View Post
That's the secondary prompt. You get that when you're in the midst of typing a command line, compound command, or quoted string.
Which, unless you're intentionally splitting your command up, usually means you forgot to close a quote.
 
Old 02-05-2016, 03:06 PM   #9
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
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

Code:
#!/bin/bash

satellite-sync -m /tmp/satdump -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6 -c \
rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6

Last edited by JockVSJock; 02-09-2016 at 01:19 PM.
 
Old 02-05-2016, 03:12 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by JockVSJock View Post
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.

Last edited by BW-userx; 02-05-2016 at 03:23 PM.
 
Old 02-05-2016, 03:18 PM   #11
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by BW-userx View Post
bold is the problem and underline means you do not have that installed or it is not actually an option / valid command

I do not run this on my linux so I can not run it to figure it out -- but all or some of your channels do not actaully exist

or are not available:meaning: perhaps server is backed up or shut down for service ... etc ...
you have to find correct channels
If I break up the code, it runs ok.

Code:
satellite-sync -m /tmp/satdump -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6
 
Old 02-05-2016, 03:37 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by JockVSJock View Post

If I break up the code, it runs ok.

Code:
satellite-sync -m /tmp/satdump -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6
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.

Modded:
Miss understold what you meant.

you could try it like this
Code:
#!/bin/bash

satellite-sync -m /tmp/satdump -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6 -c \
&& satellite-sync -m /tmp/satdump -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6
or this
Code:
 

mode1="-c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6"

mode2=" -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6"

satellite-sync -m /tmp/satdump ""${mode1}""${mode2}""
providing that this whole line works when ran as a whole line all together.

if not and the docs say that more can be added, then it maybe falling back to the order in which you present them instead.

Last edited by BW-userx; 02-05-2016 at 03:56 PM.
 
1 members found this post helpful.
Old 02-05-2016, 03:46 PM   #13
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by JockVSJock View Post
If I break up the code, it runs ok.
Groovy.
Another method I am fond of...

Stick file names in a file ("list" here)
one file name per line is my usual M.O.

Code:
for i in `cat list` ; do satellite-sync -m /tmp/satdump -c $i ; done
This method is good for one host where little changes except for the file names.

Now let's turn this into a script!
Stick the files names into a list
and run
Code:
for i in `cat list` ; do echo satellite-sync -m /tmp/satdump -c $i ;  done > mysatsync.sh
Edit mysatsync.sh and add
Code:
#!/bin/bash
to the top of file and
Code:
chmod 700 mysatsync.sh
and you'll have a neat and short working shell script.

See also http://showterm.io/74d24a959501edbea5041#fast
Have fun.
 
Old 02-09-2016, 01:17 PM   #14
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Quote:
Originally Posted by BW-userx View Post
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.

Modded:
Miss understold what you meant.

you could try it like this
Code:
#!/bin/bash

satellite-sync -m /tmp/satdump -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6 -c \
&& satellite-sync -m /tmp/satdump -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6
or this
Code:
 

mode1="-c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6"

mode2=" -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6"

satellite-sync -m /tmp/satdump ""${mode1}""${mode2}""
providing that this whole line works when ran as a whole line all together.

if not and the docs say that more can be added, then it maybe falling back to the order in which you present them instead.
Probably didn't make myself clear.

When I run these lines separately, it works:

Code:
satellite-sync -m /tmp/satdump -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6

Code:
satellite-sync -m /tmp/satdump -c rhel-x86_64-server-optional-6 -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6

I've tried to run the script like so

Code:
satellite-sync -m /tmp/satdump -c \
rhel-x86_64-server-6 -c \
rhel-x86_64-server-6-htb -c \
rhel-x86_64-server-ha-6 -c \
rhel-x86_64-server-lb-6 -c \
rhel-x86_64-server-optional-6 -c \
rhel-x86_64-server-supplementary-6 -c \
rhn-tools-rhel-x86_64-server-6
However it returns the following error:

Code:

[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]#

Code:
/usr/bin/satellite-sync -m /tmp/satdump -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64i-server-optional-6 -c \
&& rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6

Code:
[root@server scripts]# ./satellite_channel_sync_rhel6.sh
usage: satellite-sync [options]

satellite-sync: error: -c option requires an argument
[root@server scripts]#

This one worked

Code:
mode1=" -c rhel-x86_64-server-6 -c rhel-x86_64-server-6-htb -c rhel-x86_64-server-ha-6 -c rhel-x86_64-server-lb-6 -c rhel-x86_64-server-optional-6"

mode2=" -c rhel-x86_64-server-supplementary-6 -c rhn-tools-rhel-x86_64-server-6"

/usr/bin/satellite-sync -m /tmp/satdump ""${mode1}""${mode2}""
I did change the path for the satellite-sync command to go to /usr/bin.


I still don't have enough confidence to do what Habitual recommended....maybe sometime here in the future.

thanks
 
Old 02-09-2016, 01:34 PM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.
 
  


Reply

Tags
cli, command line interface



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI lines wrapping overwrites in rxvt xj25vm Slackware 15 08-05-2013 05:10 AM
[SOLVED] Not sure why this command isn't working under bash and cron cheddarcheese Linux - Newbie 4 05-12-2013 10:04 AM
./configure command isn't working in command line jumpmansbro Linux - Newbie 20 01-22-2009 08:29 PM
why isn't this find command working? jim.thornton Linux - Newbie 3 06-10-2008 06:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration