LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-15-2016, 03:07 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Another bad script (I ask again: me, my shell, or my lousy scripting?)


The one text file I give it to read, ASCII text (file command and "cat -e" both verify the line endings are right), gives me echo lines like
Code:
img_3832.jpg:PQL
It's not recognizing ":" as the field separator.

And it's not just my choice of separators. I've tried , and ^ with equal lack of success.

The script is below.

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

function gettext () {
echo -e "What annotations file will I be using?"
read -er thelist
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$thelist" ]]; then
	capfile1=${thelist% *}
else
	capfile1=$thelist
fi
}
gettext
while IFS=":" read -r file1 cate
do		echo -ne "$file1\n$cate\n"
		exiftool -fast5 -overwrite_original_in_place -q -P -IPTC:Category="$cate" -XMP:Category="$cate" "$file1"
		echo -ne "Written:\tCATEGORY"
done<"$capfile1"


IFS=$SAVEIFS
So what is it that I, my installed ShellCheck, and SC online aren't seeing?

Carver

Last edited by L_Carver; 12-15-2016 at 03:08 AM. Reason: Bad subject line -- missing a CP
 
Old 12-15-2016, 03:57 AM   #2
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
More of my own work (a dog chasing its own tail, but I really want to solve this.):

Changing line 17 to
Code:
IFS=\: read -a file1 cate
merely causes the script to hang. So unless I'm wrong, it isn't the separator (or the way it's set) at all.

Using an identical read loop in terminal "echoes" the file name separate from the category listed. So where's the difficulty in the subshell seeing and USING the separator?

Carver
 
Old 12-15-2016, 04:17 AM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Comment removed...

Last edited by hydrurga; 12-15-2016 at 05:20 AM. Reason: Hampered by my own lack of knowledge :-)
 
Old 12-15-2016, 05:14 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,259

Rep: Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838Reputation: 6838
you still did not understand what was explained to you:
use set -xv at the beginning of the script to see what's happening. That will be a good help to understand the program flow.
use " to protect your variables: like capfile1="$thelist" otherwise they may be split
IFS=: IFS=\: and IFS=":" are the same
Quote:
It's not recognizing ":" as the field separator.
is definitely not the right deduction, this is just a visible "side effect".
shellcheck will not find logical errors...
 
Old 12-15-2016, 01:13 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,453

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
Maybe you have two or more : in a row, then you need an additional variable to catch the remainder.
Code:
while IFS=":" read -r file1 cate junk
--
bash knows "$ quoting":
Code:
IFS=$'\n\b'
--
"gettext" is an unlucky name for a function because it can be confused with the gettext program.

Last edited by MadeInGermany; 12-15-2016 at 01:17 PM.
 
Old 12-16-2016, 05:02 PM   #6
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by MadeInGermany View Post
"gettext" is an unlucky name for a function because it can be confused with the gettext program.

Thank you for pointing that out. I think I intuited 'gettext' from the (remarkably old) Mac Hypercard term getfile, aka Open dialogs. I'll intuit something else instead. I use silly things like "hotdog" and "hamburger" for other variables and functions, so it'd be advisable to tap my sense of humour here too, I suppose.

Carver
 
  


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
Shell Scripting Arguments help needed bad ABCDblade Linux - Newbie 16 10-28-2014 09:29 PM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
newbie scripting: Writeing a Shell script Qu hoodedmanwithsythe Programming 12 06-10-2007 07:54 AM
Scripting in Linux, different shell mid-script ryoken31 Programming 6 04-06-2007 07:10 PM
Shell scripting: How to redirect output from within the script itself? Arodef Linux - General 4 05-23-2006 07:30 PM

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

All times are GMT -5. The time now is 04:32 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