Sponsored Content
Full Discussion: variable issue
Top Forums Shell Programming and Scripting variable issue Post 302491413 by Corona688 on Thursday 27th of January 2011 11:40:22 AM
Old 01-27-2011
I'm a bit wary of when people say "no really, I honestly need to cram an unlimited number of results into one single variable and it won't work any other way". This is usually just a bad programming habit, not an actual need.

Consider:

Code:
while read EXT
do
        find ../FILES/ -name "*.${EXT}" | while read FILE
        do
                mv -i "${FILE}" "/path/to/destination/folder"
        done
done < extlist.txt

This lets you process it one name at a time so you don't need to worry about shell limits.

Cramming unlimited numbers of arguments is a bad idea for many reasons:
  • What happens if you get a file named "stuff to do.ext"? Stuff it into one giant list and it'd become three files, "stuff", "to", "do.ext".
  • Many shells have surprisingly small limits on the maximum length you can fit in one shell variable. As the number of files gets large it'll break when you least expect it.
Using pipes to process names one at a time avoids these both.

Actually, you can simplify that using the -exec feature of find:

Code:
while read EXT
do
        find ../FILES/ -name "*.${EXT}" -exec mv -i '{}' "/path/to/destination/folder" ';'
done < extlist.txt

...and if you're using Linux, you can use the -t feature of mv and the + feature of find, which will let it move multiple files with one command very quickly:
Code:
while read EXT
do
        find ../FILES/ -name "*.${EXT}" -exec mv -t "/path/to/destination/folder" -i '{}' '+'
done < extlist.txt

---------- Post updated at 10:40 AM ---------- Previous update was at 10:20 AM ----------

Quote:
Originally Posted by skubann
I've make the test with find, and the issue is the same :
result=`find ../FILES/ -name "*.$ext"` don't parse the ext variable.

thanks
find works. Something else is wrong.

Have you tried one of my solutions?

Last edited by Corona688; 01-27-2011 at 12:27 PM..
 

10 More Discussions You Might Find Interesting

1. Solaris

Variable Substitution Issue

#!/bin/ksh VAR_ONE=HELLO TEMP=ONE echo $VAR_${TEMP} ## Output is: ONE Hi, I want the output to echo HELLO and not ONE as the above script does. I know I am missing something with dollar substitution. Can anyone help me out ? Thanks. Cal (4 Replies)
Discussion started by: calredd
4 Replies

2. Programming

Have issue with variable

Hi All, i am new to unix.. i have an issue with my unix script...let me explain the task that i want to make script.... i prepared script which will connect data base from my linux box using sqlplus cmd... however in that i want to use the variable like below.. select * from... (0 Replies)
Discussion started by: Shahul
0 Replies

3. Shell Programming and Scripting

Variable sub-menu issue

The code im having problems with is highlighted in red, upon selecting option 2 on the main menu (highlighted green) my echo "NETWORK CONNECTIVITY" command seems to get overlooked and the resulting output is "Thank you for using the Operator Administrative Tool." being displayed. Can anyone tell me... (2 Replies)
Discussion started by: warlock129
2 Replies

4. Shell Programming and Scripting

UNIX variable issue

Hi all, Something funny happen with this code: EXIST=`ssh batch@190.2.332.234 'if ; then echo 0; else echo 1 ; fi'` echo $EXIST Above code will display "1". The value of remotePath is /home/batch The value of fileName is sample.txt ========================================= ... (1 Reply)
Discussion started by: suigion
1 Replies

5. Shell Programming and Scripting

Issue in Variable in SSH

Friends, I want to write a script. The logic follows 1. Script starts 2. SSH to Remote Machine and check whether /home/testUser dir is there or not. 3. If it is there, am assigning a value to a variable. else not 4. If the variable is set, the do the copy from remote machine to my local... (2 Replies)
Discussion started by: balamv
2 Replies

6. UNIX for Dummies Questions & Answers

PLease HELP!!! PATH variable issue

Hello, I logged in to the unix solaris with my user name and then I again logged in with the sudo bash -l command now when I do echo $PATH It shows me => /usr/bin:/usr/local/bin:/usr/bin/usr/sbin:/usr/ucb:/usr/local/bin How do i find out where is this file located for setting the... (3 Replies)
Discussion started by: siddhans
3 Replies

7. Shell Programming and Scripting

Issue with AWK using a variable

Hi, I am doing an AWK in ksh as below with the string to search to be read from variable but for some reason there is no output. It works when I hard code it. awk 'substr($0,22,6)=="${VAR}"' XXX.txt' >YYY.txt On reading other posts I tried below option, 'substr($0,22,6)=="/"${VAR}/""' ... (3 Replies)
Discussion started by: junnujayz
3 Replies

8. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

9. UNIX for Dummies Questions & Answers

Issue with variable assignation

Hi All, My files(.csv) are created in download path. All the files files are having footer with count of rows or may be blank. When i am trying to put this below code in shell script and run it, the row_num is not getting assigned, but works correctly on command prompt. I am trying to put this... (2 Replies)
Discussion started by: abhi_123
2 Replies

10. UNIX for Dummies Questions & Answers

Issue with variable within a loop

I have this file (1.txt): >sample TCGGCCCGJOHNTTTTGCGGGCCGCATTGTCGCCAGGCGCDOEGGGGTTTGCGATCGCCACGGGGCTGATGGTGGCGACCCGCTGCACCCGG I am using the following script to "trim" the sequence awk '{gsub(/^.*JOHN|DOE.*$/,"",$0)} 1' This is the output: >sample TTTTGCGGGCCGCATTGTCGCCAGGCGC ... (6 Replies)
Discussion started by: Xterra
6 Replies
All times are GMT -4. The time now is 10:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy