Storing result in a variable - newbie question

Storing result in a variable - newbie question

am 18.11.2007 15:36:06 von Meeaz

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

Re: Storing result in a variable - newbie question

am 18.11.2007 16:08:57 von Joachim Schmitz

"Meeaz" schrieb im Newsbeitrag
news:cb0147e9-5297-4d16-b9c2-c309a7cdc463@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

Re: Storing result in a variable - newbie question

am 18.11.2007 16:27:29 von cfajohnson

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
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

Re: Storing result in a variable - newbie question

am 18.11.2007 21:32:40 von Bill Marcum

On 2007-11-18, Meeaz 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

Re: Storing result in a variable - newbie question

am 19.11.2007 08:20:36 von Joachim Schmitz

"Joachim Schmitz" schrieb im Newsbeitrag
news:fhpkid$ldv$1@online.de...
> "Meeaz" schrieb im Newsbeitrag
> news:cb0147e9-5297-4d16-b9c2-c309a7cdc463@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