LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2012, 09:51 AM   #16
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345

What shell are you using to run the commands? The difference seems to be in the 'find' command - in the first case (running on the shell) the globs are expanded in the 'move_files' line, while in the second one, they seem to be expanded on the 'find' line.

The issue (I think) is where you have some globs that match and some that don't. The behaviour can be seen here (my normal shell is zsh:

Code:
[joshua:~]$ cd test
[joshua:~/test]$ ls
$0          4file.bash  a.out   client.py         index.html    list.txt        nuevo-focus.html         ruby        sudoers      test2.cpp  test.cpp  test.txt  uniq.o
1file.bash  5file.bash  bash    downloadurls.txt  index.html.1  login.bash      nuevo-focus.html.backup  scipt.bash  sudoers.bak  test2.rb   test.hs   uniq      working.txt
2file.bash  $90.880     bob.sh  email             index.html.2  log.txt         ped.rc                   server.py   temp.sh      test2.sh   test.py   uniq.hi
3file.bash  $920        c++     gtk.cpp           input.txt     notworking.txt  php                      style.css   test         test.awk   test.sh   uniq.hs
[joshua:~/test]$ move_files=( *.bash *.foo )
zsh: no matches found: *.foo
[joshua:~/test]$ find "${move_files[@]}"
find: cannot search `': No such file or directory
[joshua:~/test]$ echo ${move_files[@]}

[joshua:~/test]$ bash
[joshua@joshua-desktop test]$ move_files=( *.bash *.foo )
[joshua@joshua-desktop test]$ find "${move_files[@]}"
1file.bash
2file.bash
3file.bash
4file.bash
5file.bash
login.bash
scipt.bash
find: `*.foo': No such file or directory
[joshua@joshua-desktop test]$ echo ${move_files[@]}
1file.bash 2file.bash 3file.bash 4file.bash 5file.bash login.bash scipt.bash *.foo
[joshua@joshua-desktop test]$
 
1 members found this post helpful.
Old 09-17-2012, 10:35 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,421

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
I am with Snark in that it may be best to test when the variables / globs are being expanded. Try placing some echoes in the script to see what is stored in the move_files array?

Sorry I missed the output previously, I did not notice there was a scroll on the side

I would also mention that running the code with sh may also cause some of the bash only options to not function properly.
Try also making the file executable and running it that way. You can place set -xv as the second line to follow the output

Last edited by grail; 09-17-2012 at 10:36 AM.
 
1 members found this post helpful.
Old 09-17-2012, 04:25 PM   #18
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Original Poster
Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
sorry, not ignoring your posts, just real busy at work today.

fyi we are just in a bash profile, but our terminal is scoansi. not sure if that helps atm.
 
Old 09-18-2012, 05:04 AM   #19
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Quote:
Originally Posted by grail View Post
I would also mention that running the code with sh may also cause some of the bash only options to not function properly.
Good spot - I'm not sure if it's what grail meant, but when you execute the script, you do it with 'sh', not 'bash' (despite the #! at the start of the script) so you are effectively executing it with two different shells.

Try running
Code:
bash -xvv DEA2-MOVE
instead.

Hope this helps,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: Error with eval when array name contains a hyphen Johnburrell Programming 10 05-11-2012 01:44 PM
[SOLVED] reference bash array values, using a variable with a value of the array name gusthecat Programming 5 03-07-2012 04:41 PM
[SOLVED] Bash: Calculating in array and storing result in array ghantauke Linux - Newbie 6 12-02-2010 01:28 PM
[bash] indirect array reference to array with values containing spaces Meson Linux - Software 9 06-04-2010 10:38 PM
bash: use file as input into array, parse out other variables from array using awk beeblequix Linux - General 2 11-20-2009 11:07 AM


All times are GMT -5. The time now is 07:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration