I modified the script as following, did not help either
the output is following
I suppose the problem comes from a misunderstanding about what is done when in the shells evaluation process.
When you write a process substitution in a here-document:
The following happens: a subshell is loaded and "some_command" is executed in this subshell. The output (to stdout) of this process is taken and the process substitution is replaced with this outcome. Lets say the outcome is "blahblah" then the shell would arrive at this:
Only now this resulting here document is fed to the (compound)-command. I used a while-loop for the example but it could be any other single or complex command too. Notice, that "blahblah" is not treated as a command - it is treated as a string! This will perfectly work even though the shell wouldn't know what to make of a command "blahblah".
Now consider this:
Yes, it looks like variable "x" would be assigned some value, but in fact this is not treated as a command either - it is just a string, the same way "blahblah" alone was just a string!
You had this string in the here-document and expected it to be executed - but this is not the case. The shell only evaluates the here-document, which means that process substitution gets done and variables are expanded:
In this example the string "$var" willl be replaced by the content of the variable "var", which is "blahblah", therefore the resulting string passed to the while-loop will again be "x=blahblah", but this will still not be executed and a variable "x" will still not have the value "blahblah" at all.
What you can do to achieve what you obviously want is the following:
but i admit this looks ugly and i suggest not to do it at all. My suggestion is based on ksh (don't know if you have that) and looks like this (only sketched out). Note that for-loops with an undefined number of elements is a bad idea in any shell because it can break if "*txt" evaluates to too many files. I used a while-loop therefore. I also removed the awk-scripts where they could be replaced by simple shell-expansion:
I admit, i couldn't make out what the awk-orgy is supposed to do, so i let it in place. You might want to replace it with a shell expansion eventually.
Anybody know what's wrong with this syntax?
awk -v job="$job" 'BEGIN { FS="|"}
{print $1,$2," ",$4," ",$3\n,$5,"\n"}' list
It's keeping give me this message:
awk: syntax error near line 1
awk: bailing out near line 1
It seems awk has problem with my BEGIN command.
Any... (8 Replies)
Does anybody know how to print a variable passed to awk command?
awk -F"|" 'BEGIN {print $job,"\n","Question \n"} {print $1,$2$4," ",$3}' "job=$job1" file1
I am trying to pass job the variable job1.
the output is blank.
?? (3 Replies)
I want to instert Category:XXXXX into the 2. line
something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong:
sed "2i\\${n}Category:$cat\n"
Sample:
Titel Blahh Blahh abllk sdhsd sjdhf
Blahh Blah Blahh
Blahh
Should look like... (2 Replies)
Hi,
Can you please help. I am scripting in sh and I am trying to simply copy one directory to another but for some reason my variables are not recognised?
echo "The latest version of the program is being found......."
cd $SOFTWARE/src/$progname
version=`ls $SOFTWARE/src/$progname | grep... (13 Replies)
I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename?
#!/bin/bash
filename=`echo $0`
/usr/bin/sed '/#include/ {
i\
the filename is `$filename`
}' $1
exit 0 (8 Replies)
The following subroutine prints 1 instead of the content of the Equipment variable. Can someone tell me why?
#!c:/perl/bin/perl.exe
#
use strict 'vars';
my $Equipments = "data/equips.txt";
unless (open(EQUIP_FH, "$Equipments")) {
print "errors: $Equipments\n"; # This line prints... (1 Reply)
Hi,
I am facing a challenge in fixing an issue in my installation scripts.Here is a situation:
There are 3 files which are invoked at a below given order:
Installer.ksh----->Installer.xml(Ant script)------->common.ksh
I am outputting a message from common.ksh at a terminal, after that trying to... (3 Replies)
I am having difficulties with the fllowing script:
!/bin/sh
voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/
echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log
for audiofile in `ls $voicemaildir/*.wav`; do
transcriptfile=${audiofile/wav/transcript}
... (4 Replies)
I have a script.
#!/bin/sh
cur_$1_modify_time=Hello
echo "cur_$1_modify_time"
When I run like
sh /root/script1 jj
I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time
But the output comes as
# sh... (3 Replies)
In the bash below the variable date displays in the echo. However when I use it in the for loop it does not. Basically, the user inputs a date then that date is converted to the desired format of (month-day-year, no leading 0). That input is used in the for loop to return every file that matches... (5 Replies)