LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2016, 04:05 AM   #1
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 924

Rep: Reputation: 43
problem with nohup, for loop and gzip


When I execute the following gzip in FOR loop on DIR q, then it works as expected - all .sh files will be gziped.

Code:
for i in q/*.sh ; do gzip $i; done
Code:
# ls -al q
total 196
drwxrwxr-x  3 meme meme  4096 kwi  6 10:48 .
drwxr-xr-x 13 meme meme  4096 kwi  6 10:36 ..
-rw-rw-r--  1 meme meme  1959 sie 26  2015 }
drwxrwxr-x  2 meme meme  4096 wrz 24  2015 20150801
-rwxr-xr-x  1 meme meme   111 paź 13 14:37 arg1.sh.gz
-rwxr-xr-x  1 meme meme    91 paź 13 14:39 arg2.sh.gz
-rwxr-xr-x  1 meme meme  2065 sie 26  2015 con2.sh.gz
-rwxrwxrwx  1 meme meme  2007 sie 26  2015 con3.sh.gz
-rwxr-xr-x  1 meme meme   800 sie 26  2015 con4.sh.gz
-rwxr-xr-x  1 meme meme   729 sie 26  2015 con5.sh.gz
-rwxr-xr-x  1 meme meme   542 sie 28  2015 con6.sh.gz
-rwxr-xr-x  1 meme meme  1024 sie 26  2015 con.sh.gz
-rwxr-xr-x  1 meme meme   544 sie 28  2015 con_working.sh.gz
-rw-------  1 root    root      736 kwi  6 10:45 nohup.out
-rwxrwxrwx  1 meme meme   156 sie 26  2015 telneter.sh.gz
-rwxrwxr-x  1 meme meme  1613 sie 26  2015 working.sh.gz
-rw-rw-r--  1 meme meme 10240 gru  3 16:52 working.tar
-rw-rw-r--  1 meme meme     0 sie 27  2015 x
However, when I execute this same in a background, I will get errors and no .sh files will be gziped.

Code:
nohup bash -c "for i in q/*.sh ; do gzip $i; done" &
Code:
# cat nohup.out 
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
gzip: q/working.sh.gz: No such file or directory
Does anyone know why it is not working?
 
Old 04-06-2016, 05:09 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Try single quotes instead.

Code:
nohup bash -c 'for i in q/*.sh ; do gzip $i; done' &
When using " around paramters, $ variables are evaluated before executing anything and then $i becomes nothing since it's probably not defined.
 
1 members found this post helpful.
Old 04-06-2016, 07:39 AM   #3
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 924

Original Poster
Rep: Reputation: 43
i could swear I tried that before I wrote this post... but - yes - it works this way with single quota.
Thank you very much for answer
 
  


Reply



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
[SOLVED] gzip: exp2012dec11.dmp.gzip: unknown suffix -- ignored 1300 Linux - Newbie 11 12-23-2012 09:19 AM
nohup inside loop santhosh_cv Programming 1 10-01-2012 04:42 AM
[gzip] appears in process table after gzip command completes redmanDBA Linux - General 0 02-26-2008 06:12 AM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 11:36 AM
Solaris 8 gzip issues- cannot gzip -d lynx sixosix Solaris / OpenSolaris 4 03-13-2005 03:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 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