LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Closed Thread
  Search this Thread
Old 10-15-2016, 09:39 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Another bash script somehow wrong


I'm trying to write a script to move files from one directory to another. The filenames are specified in text files. I keep getting a "Cannot stat foo.jpg: No such file or directory" error on every filename in the list.

Here's the code:
Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n")

function gettext () {
echo -e "What text will I be using?"
read -e item
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$item" =~ " " ]]; then
	capfile=${item% *}
else
	capfile=$item
fi
#echo $capfile
}
gettext
while IFS=^ read name dest
do
/bin/mv "$name" "$dest"
#echo "File $name is now $newname."
done<$item

IFS=$SAVEIFS
I know this is possible. I had a script that did it correctly, but I lost it re-installing a new Linux disty.

Llewellyn
 
Old 10-16-2016, 06:10 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051
1) why bash -i?
2) what's all this messing about with IFS?
3) bash takes care of trailing spaces and such, just ignore it.
4) what's the script supposed to read from the user? it just says "What text will I be using?"
5) what 'while IFS=^ ' supposed to mean?

...
 
Old 10-16-2016, 07:19 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,745

Rep: Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599Reputation: 5599
In addition, what is the format of your file? Are you using an absolute path?
 
Old 10-16-2016, 08:56 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,777

Rep: Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059Reputation: 7059
why don't you continue the original thread? http://www.linuxquestions.org/questi...pt-4175590404/

this script is still not ok and also we have no idea how did you run it, so hard to say anything. Probably that foo.jpg does not exist or located in another dir or something else you have forgotten to tell us

Last edited by pan64; 10-16-2016 at 09:02 AM.
 
  


Closed Thread


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
[SOLVED] What's wrong with this bash script L_Carver Ubuntu 15 11-06-2016 02:40 PM
[SOLVED] What is wrong with my bash script? HalfEmptyHero Programming 2 08-02-2011 04:03 PM
What am I doing wrong in this bash script ? bashprog Programming 4 10-10-2010 07:19 PM
My first BASH script, what's wrong with it? szf2 Linux - Newbie 2 11-12-2003 01:43 PM
Basic BASH script, what's wrong??? Satriani Linux - General 2 06-02-2003 05:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 02:08 AM.

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
Open Source Consulting | Domain Registration