Storing result in a variable - newbie question

Hi All,

I want to execute a move command in a script and zip the resultant as
follows:-

mv abc abc123
and then do a gzip on abc123

If I execute following:-
c=mv abc abc123
gzip $c

.......does not seem to work......

Please advise...

Thanks in Advance
Meeaz [ So, 18 November 2007 15:36 ] [ ID #1873434 ]

Re: Storing result in a variable - newbie question

"Meeaz" <zaeem.masood [at] gmail.com> schrieb im Newsbeitrag
news:cb0147e9-5297-4d16-b9c2-c309a7cdc463 [at] 41g2000hsh.googleg roups.com...
> Hi All,
>
> I want to execute a move command in a script and zip the resultant as
> follows:-
>
> mv abc abc123
> and then do a gzip on abc123
>
> If I execute following:-
> c=mv abc abc123
> gzip $c
>
> ......does not seem to work......
Indeed, as 'mv's result is an exit code, most probably 0 (if the mv
succeeded)

target=abc123
mv abc $target
gzip $target

Bye, Jojo
Joachim Schmitz [ So, 18 November 2007 16:08 ] [ ID #1873439 ]

Re: Storing result in a variable - newbie question

On 2007-11-18, Meeaz wrote:
>
> I want to execute a move command in a script and zip the resultant as
> follows:-
>
> mv abc abc123
> and then do a gzip on abc123
>
> If I execute following:-
> c=mv abc abc123
> gzip $c

Assuming that the destination is a file, not a directory:

mv abc abc123
gzip "$_"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
cfajohnson [ So, 18 November 2007 16:27 ] [ ID #1873441 ]

Re: Storing result in a variable - newbie question

On 2007-11-18, Meeaz <zaeem.masood [at] gmail.com> wrote:
> Hi All,
>
> I want to execute a move command in a script and zip the resultant as
> follows:-
>
> mv abc abc123
> and then do a gzip on abc123
>
> If I execute following:-
> c=mv abc abc123
That says: set the variable c equal to mv, and execute the command
"abc abc123"

> gzip $c
>
You know what the new filename will be before the mv command, so use that.
c=abc123
mv abc $c
gzip $c
Bill Marcum [ So, 18 November 2007 21:32 ] [ ID #1873443 ]

Re: Storing result in a variable - newbie question

"Joachim Schmitz" <nospam.jojo [at] schmitz-digital.de> schrieb im Newsbeitrag
news:fhpkid$ldv$1 [at] online.de...
> "Meeaz" <zaeem.masood [at] gmail.com> schrieb im Newsbeitrag
> news:cb0147e9-5297-4d16-b9c2-c309a7cdc463 [at] 41g2000hsh.googleg roups.com...
>> Hi All,
>>
>> I want to execute a move command in a script and zip the resultant as
>> follows:-
>>
>> mv abc abc123
>> and then do a gzip on abc123
>>
>> If I execute following:-
>> c=mv abc abc123
>> gzip $c
>>
>> ......does not seem to work......
> Indeed, as 'mv's result is an exit code, most probably 0 (if the mv
> succeeded)
Did I really write that nonsense? Bill's description of what this really
does is correct, mine is not, sorry about that...

> target=abc123
> mv abc $target
> gzip $target
This however should work (and is the same as Bill's solution), but Chris's
solution (of using $_) is far more elegant IMHO!

Bye, Jojo
Joachim Schmitz [ Mo, 19 November 2007 08:20 ] [ ID #1873836 ]
Linux » comp.unix.shell » Storing result in a variable - newbie question

Vorheriges Thema: Unable to change path in a bash script
Nächstes Thema: Doesn't xargs support regular expression?