LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 12-14-2016, 10:23 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Is it my scripting or my shell?


Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

function gettext () {
echo -e "What list will I be using?"
read -er 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 -r file1 idesc
do
echo "$file1"
exiftool -fast5 -overwrite_original_in_place -P -q -EXIF:ImageDescription="$idesc" "$file1"
echo -e "File $file1 now has an \e[42mExif Image Description.\e[0m"
done<capfile

IFS=$SAVEIFS
returns
Code:
bash: capfile: No such file or directory
Both shellcheck online and my installed version indicate no errors. I've cleared any older variables (command:exec bash) but the error persists.

This one definitely needs another pair of eyes.

Carver

PS: No need; the "capfile" variable after done was missing its $.
(Someone please delete this thread. I know I did something right by posting it to the "Newbie" section; what a piker error this was!)

Last edited by L_Carver; 12-14-2016 at 10:29 AM. Reason: Found the answer almost without looking.
 
Old 12-14-2016, 10:40 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,698

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
It happens to everyone...
 
Old 12-14-2016, 11:54 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I'm glad you found your answer, but just thought I would ask about the following comment:
Quote:
#Allowing for, and correcting, the trailing space in interactive mode
It seems that unless I place a space at the end on purpose, I am unable to have one that would need to be removed.
Would you be able to explain under what circumstances this occurs?
 
Old 12-15-2016, 02:49 AM   #4
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
It seems that unless I place a space at the end on purpose, I am unable to have one that would need to be removed.
Would you be able to explain under what circumstances this occurs?
Try pasting a filename into the space a read command gives you. It has been my experience that it will paste with one space at the end of the string which is the filename.

That's my experience. Maybe I'm too lazy, or too unsure that I won't make typos in such a "one shot or you lose it" situation like having a script run right the first time around. I'm sure the bash folks have not been as hypocritical with this as they have been with "IFS=$(echo \n)," which I thought was supposed to remove the necessity of putting quotes around every variable called.

Carver
 
Old 12-15-2016, 08:35 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well, I tried pasting using my mouse and still no difference, unless of course I were to copy off the end of the string I was pasting

As for quotes, they help preserve white space and special characters when in variable so setting IFS will not change that in any way. What it affect is how words are split when
fed to things like a for loop variable.
 
  


Reply



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
LXer: Shell Scripting Part 3: Decision Control Structures in Shell Scripts LXer Syndicated Linux News 0 05-05-2015 10:01 PM
LXer: Shell Scripting Part 2: Accepting Inputs and Performing Shell Arithmetic LXer Syndicated Linux News 0 04-30-2015 07:10 AM
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-12-2013 11:20 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:10 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
Open Source Consulting | Domain Registration