printing error in a bash script using awk formatting. What is the real cause?
I just do not understand the output of this simple script.
What is going on? The jid was printed correctly. But it has a wrong value in the awk line. Quote:
|
I think you need to add "" if you want to specify strings (something like this):
Code:
non.pbs","'$jid'","'$jid'","'$jid'")}' ) |
for jid in 0010 0011 0012 0013
replaced by for jid in 10 11 12 13 print the correct output. But that is not what I want. um... |
pan64: I think I have tried that and it seems that is not the problem. I think printf cannot handle number starts with 0.
|
you need to handle them as strings.
Code:
for jid in 0010 0011 0012 0013; do echo $jid; done Code:
$ for jid in 0010 0011 0012 0013; do echo $jid; cmd=$(echo | awk '{printf("qsub -N batch%s -o batch%s.o -e batch%04d.e nscc-vasp-phonon.pbs","'$jid'","'$jid'","'$jid'")}' ); echo $cmd; done Again almost the same printf works without awk. Code:
for jid in 0010 0011 0012 0013; do echo $jid; printf "qsub -N batch%s -o batch%s.o -e batch%04d.e nscc-vasp-phonon.pbs\n" $jid $jid $jid; done |
OK. Thanks a lot pan64!
Realize there is a world of difference between the double quote outside versus single quote outside. Quote:
Quote:
|
You marked the thread solved, but I think there are easier ways to achieve what you're trying to. TBH, I don't quite understand what you're after. E.g. the output you got can be generated with
Code:
#!/bin/bash |
shruggy: It is solved.
The job is not only to echo to the screen but to form a command line to issue to submit jobs in a systematic manner, while taking care of numbers that start from zero that can cause confusion. Once the script is working, I just make "echo $cmd" to become "$cmd". |
I see:
Putting 00 back to the line to confirm it is working, I have Quote:
Thanks. |
The third alternative:
Quote:
|
this looks much better. And now you can try:
Code:
for jid in {10..13} spedicifed: for jid in 0010 0011 0012 0013 but batch0008 is the first printed line. Is this what you want? (numbers beginning with an extra 0 taken as octal, not decimal). |
pan64:
My bad. The third alternative should not be Quote:
Quote:
Quote:
Quote:
Quote:
The following will NOT work. Quote:
Quote:
|
Quote:
Code:
$ printf %d\\n \'0 Quote:
Quote:
Code:
#!/bin/bash |
<< BTW, why are you including leading zeros in the job ID value? printf can do this for you:
Answer: I do not want my directories to be named, say, 1, 2, 3, ..., 100 and ls will show confusing sequential listing. Say I have 0001, 0002, ... 0276 and I easily generate these zero padded 276 numbers in a file called indexfile. Then I simply use for jid in $(cat indexfile) I can cd $jid and do any task I need such as submit a script through qsub and jobs are submitted with the correct ID in the PBS queueing system. Please see my first post. |
in that case you need to use that as string, not as integer. That will keep the original line (in the indexfile).
Additionally: Code:
while read -r jid |
All times are GMT -5. The time now is 02:09 AM. |