For loop with dashes in filenames causing weird output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop with dashes in filenames causing weird output
# 1  
Old 10-17-2011
For loop with dashes in filenames causing weird output

Hi again,

What i'm trying to accomplish here is search a large directory for certain filesames, read from a txt file and looping through it.

For instance, one of my target names from the loop file is:
1ad55f47-c342-496b-a46d-ba7de0f1b434

My loop is constructed thusly, run in a directory with similarly named files:

Code:
while read i; do ls *$i*; done < /tmp/uids.txt

This leads to the following output:

Code:
*: No such file or directory-ba7de0f1b434

The first section of the filenames has been entirely truncated from the search. Tried putting quotes around the variable, same results.

If i do something like:
Code:
while read f; do echo $f; done < /tmp/uids.txt

, the filenames are returned correctly, so somehow ls is screwing me up.

Last edited by Karunamon; 10-17-2011 at 06:09 PM..
# 2  
Old 10-17-2011
Works for me on Solaris...

Code:
bash-3.00# while read i; do ls *$i*; done < /tmp/uids.txt
1ad55f47-c342-496b-a46d-ba7de0f1b434
*2ad55f47-c342-496b-a46d-ba7de0f1b434*: No such file or directory

Could it be that the file "1ad55f47-c342-496b-a46d-ba7de0f1b434" does not exist in the directory you are running you script from? ;-)
# 3  
Old 10-17-2011
Quote:
Originally Posted by Paragon1970
Works for me on Solaris...

Code:
bash-3.00# while read i; do ls *$i*; done < /tmp/uids.txt
1ad55f47-c342-496b-a46d-ba7de0f1b434
*2ad55f47-c342-496b-a46d-ba7de0f1b434*: No such file or directory

Could it be that the file "1ad55f47-c342-496b-a46d-ba7de0f1b434" does not exist in the directory you are running you script from? ;-)
It doesn't in this instance, but the fact that the command output is so weird would seem to suggest that ls is mangling the search somehow. Also, I'll need the error output in its entirety in order to match up against my target list which files didn't exist, having the first few bits stripped off is no good here.

Last edited by Karunamon; 10-17-2011 at 06:34 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loop is causing ssh command to exit from script after first iteration.

I am trying to check multiple server's "uptime" in a loop over "ssh". When I execute multiple ssh commands with hard coded servernames script is executing fine. But when I pass server names using while loop, script is exiting after checking first server's status, why? # serverList... (8 Replies)
Discussion started by: kchinnam
8 Replies

2. HP-UX

[Solved] Weird 'ls -l' output

Hello folks, I've found an HP-UX server with a rare 'ls -l' output. Please see the attached file. Anybody knows how can I change the output to not have this extra tabulations? Thanks in advance! (10 Replies)
Discussion started by: carpannav
10 Replies

3. Shell Programming and Scripting

Generate filenames in a loop

Hi all, I want to generate output files in a loop, run the same command on the same input file 1000 times and output in files with a new name each time, maybe a number appended to it. The output will be different each time as I`m sampling randomly from the input file. I want to do the... (3 Replies)
Discussion started by: newbie83
3 Replies

4. UNIX for Dummies Questions & Answers

weird 'ls' output

Hi, Anyone knows why I can't display the contents of my directory and how to fix this? http://i50.tinypic.com/4smfth.jpg Thanks in advance for any advise. Deanne Double post. Continued here. (0 Replies)
Discussion started by: Deanne
0 Replies

5. Shell Programming and Scripting

format of output is weird

hi all, have a ksh script which connects to a database and runs a sql and dumps it to a '.csv' file. The problem is the result is in multiple rows with long spaces in between when it should be just a single line and this screws up the format in the '.csv' file. script is : #!/bin/ksh... (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. Shell Programming and Scripting

Weird loop break,- please Help

Hi all, im doing this script in which i read from a logfile line by line, my problem is this: The script was working fine until i added this statement to SSH into another machine to look for some data, it enters and retrieves the data just fine, but for some strange reason after it goes thru the... (1 Reply)
Discussion started by: sx3v1l_1n51de
1 Replies

7. Shell Programming and Scripting

loop through numbered filenames

Hi I'm very new to this script thing, so please be gentle. I am trying to get a command - the mach2qtl command in the code below - to loop through a set of files. Each command should take the same two .dat and .ped files, but the .mlinfo and .mlprob files with filenames including 'chrom1' ... (7 Replies)
Discussion started by: polly_falconer
7 Replies

8. Shell Programming and Scripting

weird echo output?

#!/bin/bash INPUT=$1 if then INPUT=0$1 TRACKNUMBER=$INPUT fi TRACKNUMBER=$INPUT echo "Track Number:" $TRACKNUMBER if then echo "File Does Not Exist!: split-track"${TRACKNUMBER}".wav" exit 0 fi CUEFILE="$2" (6 Replies)
Discussion started by: TinCanFury
6 Replies

9. Shell Programming and Scripting

Why for loop is acting weird

Hey i have a small script in which i check if a file with that pattern exists or not. If present then i go ahead with further processing. In the present situation i have only one file with that name and for loop is reading twice. Here is the script. And the output of debug mode. Please help.... (5 Replies)
Discussion started by: dsravan
5 Replies

10. AIX

Weird bootlist output

just setup a new system today - 9117 570, using HMC for console but not partitioned. I installed this system twice. the first time it started off as 5300-00, then updated to ML03. before the update, I believe I mirrored the rootvg, and then altered the bootlist, at that point, the display was... (4 Replies)
Discussion started by: davew1099
4 Replies
Login or Register to Ask a Question