I have a for loop that constructs a variable "filelistonly" having entries separated by "\n" new line.
The second, third & fourth while loops are my attempt to iterate the variable "filelistonly" upon new line "\n", however non of them work.
Below is my script:
Below is the debug Output:
Quote:
# bash -x ./test.sh /root,/tmp
++ echo /root,/tmp
++ tr , '\n'
+ for i in '$(echo $1 | tr '\'','\'' '\''\n'\'')'
++ find /root -name hello.db -type f
+ fileresult=/root/Music/hello.db
++ echo /root/Music/hello.db
+ filelistonly='/root/Music/hello.db\n'
+ for i in '$(echo $1 | tr '\'','\'' '\''\n'\'')'
++ find /tmp -name hello.db -type f
+ fileresult=/tmp/hello.db
++ echo /tmp/hello.db
+ filelistonly='/root/Music/hello.db\n/tmp/hello.db\n'
+ read -r line
+ echo '*** /root/Music/hello.db\n/tmp/hello.db\n ***'
+ read -r line
+ read line
++ echo '/root/Music/hello.db\n/tmp/hello.db\n'
++ tr , '\n'
+ echo line=/root/Music/hello.dbn/tmp/hello.dbn
line=/root/Music/hello.dbn/tmp/hello.dbn
+ read line
+ read -r line
+ '[' '/root/Music/hello.db\n/tmp/hello.db\n' '!=' '\n' ']'
+ echo 'We are Good. /root/Music/hello.db\n/tmp/hello.db\n File Found.'
We are Good. /root/Music/hello.db\n/tmp/hello.db\n File Found.
+ read -r line
The below code works and resolves the new line problem reported above however the if condition fails which is shown in debug below.
Output showing if condition failing.....
Quote:
+ '[' /tmp/hello.db '!=' '\n' ']'
+ echo 'We are Good. /tmp/hello.db File Found.'
We are Good. /tmp/hello.db File Found.
+ read -r line
+ '[' '!=' '\n' ']' ./test.sh: line 22: [: !=: unary operator expected
+ echo 'New Line Found.... Ignoring'
New Line Found.... Ignoring
I guess the issue could be in the first loop where I'm constructing the variable "filelistonly", however I'm not sure of a solution yet.
Last edited by mohtashims; 08-29-2019 at 02:06 PM..
I am piping STDOUT from commands such as ifconfig and dmesg through grep, sed and awk to get the information I need.
I need to now perform some looping and branching now and have been trying to figure out how to do this on the command line.
You may ask "Why the command line? - Why not put it... (2 Replies)
hi,
my first question is :-
i would like to know how do i loop through the output of a variable.
for ex:- if i have a variable called x and echo $x gives the output like
feb 19 07
feb 20 07
feb 21 07
i would like to know how do i loop through this since it is separated and i... (1 Reply)
I have a csh that is called from autosys. It fails when it hits this code
env | grep Rep
if ( $status == 0 ) then
echo ""
else
setenv REP ""
endif
However if I run it from the command line, as opposed to from autosys (job schduler) it runs fine. I thought it might be some kind of... (2 Replies)
Dear all,
I have a text file like below.
eg.txt
abcd
efgh
ijkl
mnop
I need a script, which should read the text file eg.txt and assign each line as a parameter. This , i wil use further to pass it a java command to invoke. All inside a for loop
Need your help on this.
With... (2 Replies)
I have a .csv file and i use the below while loop to navigate through it
But i need to loop from the second line since the first line is the header
How will i do it?? please help
while IFS=, read Filename Path size readonly
do
echo "Filename -> ${Filename}"
echo "Path -> ${Path}"
echo... (8 Replies)
I have been trying this program for a long time. I am trying to read a file named "odon" line by line; read the first line, send it to do a command saved in a file "perm", once the first line has finished going through the content of the file perm, the result is saved with the number of the line.... (17 Replies)
I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes
CC=`which gcc`
CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
This works when I try to execute normally :
echo | format | nawk '/pci@1f,4000/{print x}; {x=$0 }'
But fails when define a variable and put it in a file:
cat test
c=pci@1f,4000
echo | format | nawk "/$c/{print x}; {x=$0 }"
./test
nawk: syntax error at source line 1
context is
... (6 Replies)
I am unable to expand the value of entry variable inside the nawk command.
I tried three different nawk command as below but none of them substitute the value of entry variable.
ls *.txt | while IFS='' read -r entry; do
#nawk '/<name>/{A=1;++i} A{print >> ("cmd"i"_"$entry)}... (9 Replies)