f



How to concatenate two (mor more) commands on one line?

Assume I want to execute 2 commands. The second command should only processed if the first was finished successfully.

Furthermore the concatenation should take place on one line WITHOUT an "If" condition.

I though something like the following should match the conditions

"command 1" && "command 2"

But this doesn't work. E.g. if commands contains some parameter which in turn wrapped in double quotes e.g.

"ls -l "/user/home/user/sub dir name" " && "....

gives an error

How else can I achieve command concatenation?

Peter

5
peter_ha
1/31/2010 9:06:10 AM
comp.os.linux.misc 33599 articles. 1 followers. amosa69 (78) is leader. Post Follow

6 Replies
17285 Views

Similar Articles

[PageSpeed] 20

* 2010-01-31 09:06 (UTC), Peter Hanke wrote:

> I though something like the following should match the conditions
>
> "command 1" && "command 2"
>
> But this doesn't work. E.g. if commands contains some parameter which
> in turn wrapped in double quotes e.g.
>
> "ls -l "/user/home/user/sub dir name" " && "....
>
> gives an error

Do not use quotes around the commands, just

    command1 arg1 arg2 && command2 arg1 arg2

    ls -l "/home/user/sub dir name" && command

will do. If you need to group some commands use {}:

    command1 && { command2; command3; command4; }
0
Teemu
1/31/2010 9:15:57 AM
On 2010-01-31, Peter Hanke <peter_ha@andres.net> wrote:
> Assume I want to execute 2 commands. The second command should only processed if the first was finished successfully.
>
> Furthermore the concatenation should take place on one line WITHOUT an "If" condition.
>
> I though something like the following should match the conditions
>
> "command 1" && "command 2"
>
> But this doesn't work. E.g. if commands contains some parameter which in turn wrapped in double quotes e.g.
>
> "ls -l "/user/home/user/sub dir name" " && "....
>
> gives an error
>
> How else can I achieve command concatenation?
>
> Peter
>

Just use
command1 && command2 
without the quotes.

peter
0
Peter
1/31/2010 10:08:47 AM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Dom 31 Ene 2010 06:06,
Peter Hanke wrote:

> Assume I want to execute 2 commands. The second command should only
> processed if the first was finished successfully.
> 
> Furthermore the concatenation should take place on one line WITHOUT an
> "If" condition.
> 
> I though something like the following should match the conditions
> 
> "command 1" && "command 2"
> 
> But this doesn't work. E.g. if commands contains some parameter which in
> turn wrapped in double quotes e.g.

  OK, no problem, you can use round parenthesis to do
that task.

> 
> "ls -l "/user/home/user/sub dir name" " && "....

  Surely it does... try:

( ls -l "/user/home/user/sub dir name" ) \
 && ( ls -l "/user/home/user/another sub dir name" )


  Also, you can do:

( ( ls -l "/user/home/user/sub dir name" ) \
 && ( ls -l "/user/home/user/another sub dir name" ) )


  Just play a bit with those parenthesis... ;)

> 
> gives an error
> 
> How else can I achieve command concatenation?
> 
> Peter

Best regards,
- -- 
| Daniel Molina <dmw [at] coder [dot] cl> |
| IT Consulting & Software Development    |
| Phone: +56 2 9790277 | http://coder.cl/ |
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iQIcBAEBCgAGBQJLZY9tAAoJEHxqfq6Y4O5Nm/4P/1SUIEF6U/dB+W/IZsRQyKxO
es/X4n9q672kBG4esNHnrEtS1jinoH4pYiuK7mN6CdvHMKkViNU+3znu4TrPVw9x
OKCFEaHAVLkQcto008Iqjp4URq32hAfds6SsMDW8+3CLWnjPNkXtd+SzF+a2zk4x
uddSj5EviND7GY8/C4f4rdGFXCdgJnWrZGoscV2BzQPBKC0634cQX3LZd5p093+g
7Dsgg5ztuf6a16N3zu4SXvJ6fuzK7XQDY6HgZdHFO21R6PJRzeb+dpVsQj0hW8ox
Jd03t/3c1pt8H/k2bX2KaEImpgHjWj9wth6MksfCdqbuAnijGQ/pYrVMxE2ooyWh
RWr/RikoIdRkMDJ38f+/osVj+TUk76dGMAsOmTEWhJcqm/CLUMEZVDP/Ct5t8rFD
gHfn3zljh3x0Qg1eloc2uvAFfQV6NW0cnx1N8ojmh+5/7sDCjLJk/ULvfKEs64QC
i84Ythk/QiX37TZjcoj6mj+C+FwPui5i57HkyowkDRg34AYj9/TNv50OHKLYZWgA
fKxlaxvplAwbvTOeUFNQAwpZ5i4oLOWMMTEw9hj3qHG48xyjAz2I4qb1hpxaCRhg
z2MOqWl40PjgTFPmLeGyWw/4PhUuYUw3TxYZt81RXqEkJufPjl3wkSGmg49/Fy3V
QnkhvijWOSBvdoC4AhDn
=mDcW
-----END PGP SIGNATURE-----

0
Daniel
1/31/2010 2:10:53 PM
On 2010-01-31, Peter Hanke <peter_ha@andres.net> wrote:
> Assume I want to execute 2 commands. The second command should only processed if the first was finished successfully.
>
> Furthermore the concatenation should take place on one line WITHOUT an "If" condition.
>
> I though something like the following should match the conditions
>
> "command 1" && "command 2"
>
> But this doesn't work. E.g. if commands contains some parameter which in turn wrapped in double quotes e.g.
>
> "ls -l "/user/home/user/sub dir name" " && "....

Why are you wrapping the command in qoutes? That says to regard the
whole thing as one string, and there exits no command which is the
string "ls -l" 

Just do 
ls -l /usr/home/user/sub dir name && rm name
or whatever you want ( what is that dir name supposed to be about?)


>
> gives an error
>
> How else can I achieve command concatenation?
>
> Peter
>
0
unruh
1/31/2010 5:01:37 PM
peter_ha@andres.net (Peter Hanke) writes:

> Assume I want to execute 2 commands. The second command should only processed if the first was finished successfully.
>
> Furthermore the concatenation should take place on one line WITHOUT an "If" condition.
>
> I though something like the following should match the conditions
>
> "command 1" && "command 2"

In BASH, that might work, if you use *no arguments* and there are *no
trailing spaces* inside quotes.

The problem is that it treats what is between quotes as a piece, and
does not split it into smaller pieces as it usually does when there are
no quotes.

If you quote the command name and its arguments in one big string, it
will look for an executable named after that big string.

>
> But this doesn't work. E.g. if commands contains some parameter which in turn wrapped in double quotes e.g.
>
> "ls -l "/user/home/user/sub dir name" " && "....
>
> gives an error

Here it does the same thing because the left side is concatenated into
one string, and it looks for something named "ls -l /user/home/user/sub
dir name ", instead of just "ls". 

The problem isn't "recursive quoting", because it's not recursive, those
quotes are all handled at the same level. (Recursive would be if you had
escaped the quotes surrounding the part which was already quoted before
quoting the whole command.)

> How else can I achieve command concatenation?

This I don't need to answer because it was already answered in other
post :-)

-- 
Nuno J. Silva
gopher://sdf-eu.org/1/users/njsg
1
nunojsilva
1/31/2010 6:59:27 PM
In article <4b654802$0$6574$9b4e6d93@newsspool3.arcor-online.net>,
 peter_ha@andres.net (Peter Hanke) wrote:

> Assume I want to execute 2 commands. The second command should only processed 
> if the first was finished successfully.
> 
> Furthermore the concatenation should take place on one line WITHOUT an "If" 
> condition.
> 
> I though something like the following should match the conditions
> 
> "command 1" && "command 2"
> 
> But this doesn't work. E.g. if commands contains some parameter which in turn 
> wrapped in double quotes e.g.
> 
> "ls -l "/user/home/user/sub dir name" " && "....
> 
> gives an error
> 
> How else can I achieve command concatenation?
> 
> Peter

Don't quote the commands, it's just:

command 1 && command 2

e.g.

ls -l "/usr/home/user/sub dir name" && ...

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
0
Barry
2/1/2010 1:24:37 AM
Reply:

Similar Artilces:

Command for joining two lines to one?
I can believe I'm reduced to having to ask, but I couldn't find it in the man-pages (it's probably there though)... I have a file containing many pair of lines where one line contians the URL of some site, followed by a line containing the name of that site. I need a command/script to take each pair of lines, and turn it into one single line -- containing the URL, a delimiter (preferbly tab) and the name. I've looked at 'cut', 'paste' and 'join' (and a couple of other commands) -- because I wagely remember some basic command having an option for joini...

How do I reduce this to one line from two lines?
Hi Everyone, I it possible to reduce the following to a single line? A = max([firm_profit(:,t),firm_price(:,t)]) B = A(1,1) Kind regards, Ulrik. "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <i1mov9$m1f$1@fred.mathworks.com>... > Hi Everyone, > > I it possible to reduce the following to a single line? > > A = max([firm_profit(:,t),firm_price(:,t)]) > B = A(1,1) > > Kind regards, > > Ulrik. yes, of course... A=max([firm_profit(:,t),firm_price(:,t)]);B=A(1,1); us "us " <us@neurol.unizh....

One - Two, One
It's the Gizmondo crew! Yo! Check out this software on tha Gizmondo stand at a recent Cebit exhibition. http://video.google.com/videoplay?docid=-2239941528715060334 Different ta wizzy i was jizzle a boi. PCW 1986 it ain't. The booty-slapp'n hos is doggy stylin' tha attention. The Gizmondo was designed by tha poser of tha ZX Spectrum but this software is bustin' hizzy changed. http://www.theproductdesigners.com/ Noth'n is tha same so show some love. Playas is mackin' this kind of clockin'. http://video.google.com/videoplay?docid=-6775033602778495998 ...

One line command line filter
It seems unreasonably hard to write simple one-line unix command line filters in python: eg: ls | python -c "<something> print x.upper()" to get at sys.stdin or similar needs an import, which makes a subsequent for-loop illegal. python -c "import sys; for x in sys.stdin(): print x" <<- SyntaxError Am I missing something obvious? The best I've come up with is to use sitecustomize.py to add to __builtin__ def stdin(): import sys for x in sys.stdin(): if not x: return yield x.strip() import __builtin__ __builtin__.stdin = stdin This allows ls ...

how to attach two files with Linux command line like `mail`
With Linux command line, how to send an email and attach two plain- text files?? what about more than 2 files and any formats, like images, pdf, MS word. many thanks, lihao lihao0129@gmail.com schreef: > With Linux command line, how to send an email and attach two plain- > text files?? what about more than 2 files and any formats, like > images, pdf, MS word. > > many thanks, > lihao mail mail shows: mailx [-BDdFintv~] [-R address ] [-s subject] [-a attachment ] [-c cc- addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[...

How to Add two lines using DCL on open VMS reading one line from one file and second from another file.
Hi All, Can some one please guide me how can i do this using DCL. Problem: We are having two file named Dire.txt Total of 39 files, 61673 blocks. Total of 50 files, 4555 blocks. Second File is size.txt Directory SYS$SYSDEVICE:[000000] Directory SYS$SYSDEVICE:[mandeep] We want output in one file like. Directory SYS$SYSDEVICE:[000000] size of directory will be "Total of 39 files, 61673 blocks". ...... Bob Gezelter wrote: > On Sunday, October 19, 2014 6:26:26 AM UTC-4, mandeep...@gmail.com wrote: >> Hi All, >> >> >> >>...

How to Add two lines using DCL on open VMS reading one line from one file and second from another file.
Hi All, Can some one please guide me how can i do this using DCL. Problem: We are having two file named Dire.txt Total of 39 files, 61673 blocks. Total of 50 files, 4555 blocks. Second File is size.txt Directory SYS$SYSDEVICE:[000000] Directory SYS$SYSDEVICE:[mandeep] We want output in one file like. Directory SYS$SYSDEVICE:[000000] size of directory will be "Total of 39 files, 61673 blocks". ...... mandeepsangwan1@gmail.com wrote 2014-10-19 12:26: > Hi All, > > Can some one please guide me how can i do this using DCL. > > Problem: We...

Getting started with Linux and command line commands
Getting started with Linux and command line commands ---------------------------------------------------- http://www.extremetech.com/computing/128247-getting-started-with-linux-commands Helps the gradual user to gradually get into Linux. Also lots of tips the Burson-Marstelar employees who are bound to struggle with Linux despite their incessant bleating because they don't know their Linux and would dearly love to learn. On Wed, 09 May 2012 19:09:58 +0100, 7 wrote: > Getting started with Linux and command line commands > ---------------------------------------------------- The...

does pc linux or ppc linux require command line?
Got tired of command line interface with MS-DOS. Does linus require a lot of command line setup or has it developed to the point where it can be installed and enjoyed without a lot of tinkering with setup screens or command line work? ripi wrote: >Does linus require a lot of command line setup or has it developed to >the point where it can be installed and enjoyed without a lot of >tinkering with setup screens or command line work? Why not download a LiveCD and see for yourself, troll? chrisv wrote this copyrighted missive and expects royalties: > ripi wrote: ...

Q: send two commands to vi in command line
Hi, I wish to send two commands to vi or vim. for instance: vi -c ".,$s/abc/ABC | :wq" <filename> this opens <filename>, does replace and then save the file. However, vi/vim says "pattern not found". I can run these two commands one by one, but not altogether. Any suggestions? Thanks. Yan zhou <yzhou@medplus.com> wrote: > Hi, > > I wish to send two commands to vi or vim. for instance: > > vi -c ".,$s/abc/ABC | :wq" <filename> > > this opens <filename>, does replace and then save the ...

Applying bold font to one line of a two-line title
I have a two line title for a plot that uses a variable as the first line, and then some text and another variable concatenated in the second line, i.e. case_number = ('Case Number 1'); cpu_time = toc; title({case_number; ['CPU TIme = ', num2str(cpu_time)]}) I would like to have only the first line appear in bold font. I know I can use the 'fontweight','bold' property name and description to get the whole title in bold, but I would really like to distinguish the Case Number in bold over the second line. Is this possible, and if so, how? Another option would ...

two sed commands , want to reduce to one sed command
Hi, I have the following two sed commands that delete tabs in a file then deletes empty lines. I am having to use two seperated commands to do this including the move of the files. Is there a way I can reduce the two sed commands into one sed command to make it more efficent, or is there a way just to make the following commands more efficent. sed 's/ //g' /tmp/pat.txt > /tmp/pat.tmp mv /tmp/pat.tmp /tmp/pat.txt sed '/^$/d' /tmp/pat.txt >/tmp/pat.tmp mv /tmp/pat.tmp /tmp/pat.txt thanks pete. On comp.unix.shell, peter sands <peter_sands@techemail.com> wrote: > Hi, > I have the following two sed commands that delete tabs in a file then > deletes > empty lines. I am having to use two seperated > commands to do this including the move of the files. > > Is there a way I can reduce the two sed commands into one sed command > to make it more efficent, or is there a way just to make the following > commands > more efficent. > > sed 's/ //g' /tmp/pat.txt > /tmp/pat.tmp > mv /tmp/pat.tmp /tmp/pat.txt > > sed '/^$/d' /tmp/pat.txt >/tmp/pat.tmp > mv /tmp/pat.tmp /tmp/pat.txt > > thanks > pete. sed -e <first script> -e <second script> inputfile > .... If you have GNU sed you can use the -i option which will edit the file in place with no need to send output to temp file and mv it back. Si...

how do i share a dsl line with two offices? one mdem and two routers???
i am sharing an office with a "room mate or office mate" and desire to provide access for him to my dsl line. i am thinking that putting him on the network will open up some privacy issues for both of us, but if i could figure out a way to give him internet access, or even "T" off of the ethernet line coming out of the modem, it would be super. then he would have his own linksys routher and be able to adminsiter it as he sees fit and add printers etc. any thoughts or ideas. This will likely be wired, not wireless. Thanks rick On 8 Aug 2003 17:28:26 -0700, r...

Command-line tool able to take multiple commands at one time?
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of working Python scripts to paste into my interactive console and let those run so I don't have to copy line-by-line. Not sure if iPython would meet that criteria or not or even if such a beast exists. It would be helpful for debugging some of my simpler, yet still lengthy at times, scripts. Thanks in advance. -Pete Schott Peter A. Schott wrote: > Per subject - I realize I can copy/past...

Two palms, one computer, two palm OS (4 and 5)
My wife and I each have a pda and we have one PC. She just got a tungsten T3 (palm 5). I have a m130 (palm 4). We were able to get the new palm to work without breaking the old one exept for one big thing. A few third party software programs (docs to go, avantgo) have two versions; one for palm 4 and one for palm 5. Installing the new versions caused the palm 4 pda to break for those applications. The palm desktop did not list new software being installed on the palm 4 device but it was clearly installed. Is there anyway to use third party software with different versons for palm 4 and 5 to w...

use one line Perl command to add a line at the begin of a file
Hallo all, I wanted to add a line (e.g #include "some.h") at the begin of all .c files in a directory. I try to change one .c file with one line Perl command perl -i.org -p -e 'BEGIN{print "#include \"some.h\"\n";}' But this doesn't work, "#include "some.h"" will be printed into STDOUT. I did it with a 'long' Perl script: my $f = shift; my $fm = $f.".org"; `touch $fm`; open F, $f or die "can not open file $f $!"; open FM, "> $fm" or die "can not open file $fm...

Linux Terminal
I'm using the FC8 GNOME Terminal 2.18.4. The key binding "Cntrl" and "Page Up" scrolls up on page. In a similar way I want to scroll a single line at a time I want to add a key binding composed from the buttons "Shift" and "Page Up" to scroll up a single line My questions are: a. How do I scroll a single line? b. How do I create a key binding to this command? Thanks, Avner On Fri, 18 Apr 2008 09:49:50 -0700, Avner wrote: > I'm using the FC8 GNOME Terminal 2.18.4. > > The key binding "Cntrl" and "Page Up" scrolls...

need one line awk or sed command to conditionally join 2 lines
I have an output from a pipe that looks like this: time:06.11.13.19:42:48 150.0MB 76800 76489 311 time:06.11.13.19:42:49 150.0MB 76800 76478 322 time:06.11.13.19:42:50 150.0MB 76800 76468 332 time:06.11.13.19:42:51 150.0MB 76800 76458 342 time:06.11.13.19:42:53 150.0MB 76800 76448 352 I want it to look like: time:06.11.13.19:42:48 150.0MB 76800 76489 311 time:06.11.13.19:42:49 15...

Concatenate space due to carriage returns and new line characters into one line
Input file has multiple lines of entries for a record, created due to "memo" fields in access. This needs to be removed. To give an example; INPUT FILE FORMAT: 16250|11||Q959||3/12/2001 0:00:00|Verify Section includes abcd before fuselage 559|UPS Audit No Action Required, Text and Art work to be accomplished in 23-71-03-40 Per. R. Gelfand|43441|1 16251|8||Q960||3/12/2001 0:00:00|Revise Fig 401/Verify CBs|UPS Audit|43442|1 16252|8||Q961||3/12/2001 0:00:00|Revise IPC Ref/Verify CBs|UPS Audit No action required, previously incorporated. H. Dorsey, 10/3/02.|43443|1 16253|8||Q962||3/1...

Command Line Commands And Editor Commands
Hello, I used to use vax/vms for many years. I have just ordered a few books on these commands but would like links to Internet sites that list and explain the ones that I would be using as a programmer at the command line level. Thank you, Christopher Lusardi Chris L wrote: > Hello, > > I used to use vax/vms for many years. > > I have just ordered a few books on these commands but would like > links to Internet sites that list and explain the ones that I would be > using as a programmer at the command line level. > > Thank you, >...

Two..... Two...... Two Desktops in One...
I use an external Firewire drive (Mercury Elite 911 chip) to back up our iBook which is running OS 9.2. As we have not set up a network yet, I unmount the Mercury and then shut it down and disconnect the FW cable. Then I plug in the USB cable to the Mercury and then the iBook and then power on the Mercury. The desktop from the Mercury is then plastered all over the iBook desktop, sort of merging to two together. What am I doing wrong and what should I be doing to avoid this please? In article <madwen-7A453D.19253013012004@news-east.ash.giganews.com>, Madwen <madwen@onomat...

Hardware switch one single-line phone <---> two lines
In order to make it easier to switch directly to POTS in case of a pbx failure, I need a hardware switch to connect one phone to two different sockets. Anyone have any experience with thiese? thx BlueRinse wrote: > In order to make it easier to switch directly to POTS in case of a pbx > failure, I need a hardware switch to connect one phone to two different > sockets. Anyone have any experience with thiese? > > thx Can't you just move the plug from one socket to the other? BlueRinse <brinseM-newminuitLoseThis@sneakemail.com> wrote: > In order to make it easier to switch directly to POTS in case of a pbx > failure, I need a hardware switch to connect one phone to two different > sockets. Anyone have any experience with thiese? If you buy a DPDT switch at Radio Shack and wire it yourself, it should cost $2 or so. miguel -- Hit The Road! Photos from 35 countries on 5 continents: http://travel.u.nu Latest photos: Thailand, Indonesia, Malaysia, Israel, Palestine > > BlueRinse wrote: > > In order to make it easier to switch directly to > > POTS in case of a pbx failure, I need a hardware > > switch to connect one phone to two different > > sockets. Anyone have any experience with thiese? > Miguel Cruz wrote: > If you buy a DPDT switch at Radio Shack and wire it > yourself, it should cost $2 or so. RS's #43-433 is $18.49 if BlueRinse isn't that handy. ht...

Newbi Question
Hi, This is a newbi question. Can some one please tell me the command line command for launching the file explorer on RH Linux? Thanks, T. On Tue, 17 Feb 2004 17:18:47 -0600, "L" <L_X2828@yahoo.com> wrote: >This is a newbi question. Can some one please tell me the command line >command for launching the file explorer on RH Linux? First, read this (IMPORTANT!): http://www.catb.org/~esr/faqs/smart-questions.html Second - there are so many questions to ask one doesn't know where to start: * What version of Red Hat? 5.x? 6.x? 7.x? 8? 9? Advanced Server...

One command in more than line
hi, everyone A simple problem, however i have no idea, :( How can i separate a command into multi-line, e.g. cp --reply=no, -v src_file des_file ===> cp --reply=no -v src_file des_file Thanks Cheng Forget to mention: I'll write the commando in a c-shell script Thanks Cheng "uvbaz" <uvbaz@stud.uni-karlsruhe.de> writes: > I'll write the commando in a c-shell script You should not. Avoid csh. Use bash or ksh! cp \ --reply=no \ -v \ src_file des_file The newline must be right after '\'. Be sure not to have any space after '\'!...

Web resources about - How to concatenate two (mor more) commands on one line? - comp.os.linux.misc

concatenate - Online Journalism Blog
Posts about concatenate written by Paul Bradshaw

Concatenate: The Ultimate Excel Function for Managing PPC Campaigns
... build URL tags. There are lots of Excel functions out there that can make managing and reporting on PPC campaigns easier. My favorite is Concatenate ...

Resources last updated: 2/23/2016 11:15:03 PM