LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2018, 11:36 AM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Another non-working script


Doesn't work:
Code:
#!/bin/bash 

function dothedeed () {
echo -e "Here's the Keyword string for file $f:\n$s\n"
echo -e "Adding SupplementalCategories to \e[5;42m$f\e[0m."
supcount=$(echo "$s" | tr ',' ' ' | wc -w)
echo "$thef: There are $supcount SupplementalCategories."
echo "Here's the Supplemental Category string."
echo -e "$s"
	exiftool -sep "," -fast5 -overwrite_original_in_place -q -P -SupplementalCategories+="$s" -SupplementalCategories+="$s" "$f"
	echo -e "SupplementalCategories added to file \e[4m$f.\e[0m"
}

function dav () {
echo -e "What text file will I be using?"
read -e item
while IFS="^" read f s
do
echo -e "File is \e[31m$f\e[0m"
if [[ ! -f "$f" ]]; then
	echo "I don't see $f in this directory."
	echo "Moving to next list item."
	continue
fi
((x++))
dothedeed
done<"$thef"
}
echo "Uses Exiftool."
echo

dav

#putk
#echo "Here's the Keyword string."
#echo -e "$s"

IFS=$SAVEIFS
(scriptname:addsupcats )
Above is an edit of:
Code:
#!/bin/bash 

function dothedeed () {
echo -e "Here's the Keyword string for file $f:\n$k\n"
echo -e "Adding Keywords to \e[5;42m$f\e[0m."
keycount=$(echo "$k" | tr ',' ' ' | wc -w)
echo "$thef: There are $keycount keywords."
echo "Here's the Keyword string."
echo -e "$k"
	exiftool -sep "," -fast5 -overwrite_original_in_place -q -P -Keywords+="$k" -Subject+="$k" "$f"
	echo -e "Keywords added to file \e[4m$f.\e[0m"
}

function dav () {
echo -e "What text file will I be using?"
read -e item
#Allowing for, and correcting, the trailing space in interactive mode
if [[ "$item" =~ " " ]]; then
	thef=${item% *}
else
	thef=$item
fi
while IFS="^" read f k
do
echo -e "File is \e[31m$f\e[0m"
if [[ ! -f "$f" ]]; then
	echo "I don't see $f in this directory."
	echo "Moving to next list item."
	continue
fi
((x++))
dothedeed
done<"$thef"
}
echo "Uses Exiftool."
echo

dav

#putk
#echo "Here's the Keyword string."
#echo -e "$k"

IFS=$SAVEIFS
(scriptname:addkeys )
Konsole execution error is
Code:
line 14: : No such file or directory
Shellcheck returns the following:
Code:
n /home/steve/bin/addsupcats line 16:
read -e item
^-- SC2162: read without -r will mangle backslashes.

n /home/steve/bin/addsupcats line 16:
read -e item
^-- SC2162: read without -r will mangle backslashes.
I can't puzzle out why these could be causing an error, as read without "-r" works fine in the addkeys script.

Carver
 
Old 02-05-2018, 12:46 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Moving this to Programming to get your question better exposure.

Recommend you use "set -xv" to add debug inline in your script. I realize you used shellcheck, I've never used that and don't know how helpful it is.

You can even insert a "set -xv" before line 16 and then a "set +xv" after line 16 to minimize the debug output.
 
Old 02-05-2018, 10:28 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
The shellcheck message is a warning to advise of good habits, so can be ignored if you don't believe this is an issue.

Where are you expecting the 'item' variable to be populated from?

I would add that there is nowhere in the first script presented that populates the 'thef' variable that the while loop is trying to read from.
The second script does but then I am back to my first question as the assignment is based on 'item' being populated.
 
Old 02-06-2018, 01:59 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,892

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
you can read a description about all the shellcheck messages like this: https://github.com/koalaman/shellcheck/wiki/SC2162 (just replace SC-number at the end). This will explain why -r is recommended and when can you omit or ignore it.
Just an additional remark to shellcheck: shellcheck cannot check if your script really works, so no errors does not mean your script is ok. It means only there were no semantic problems found.
You can also use set -xv as it was already suggested (for debugging), and additionally you can use set -u and set -e too.
 
Old 02-06-2018, 03:35 AM   #5
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Yes, I see where 'thef' stays empty (mistake now remedied)

Quote:
Originally Posted by grail View Post
Where are you expecting the 'item' variable to be populated from?
In addkeys, I left the old (bash 4.0 and earlier) routine to trim any deadspace from the end of a value caught by read. The thef variable was set there, from the previous variable item. As that "trimming" routine (and here I use the term routine loosely) isn't in addsupcats, I acknowledge that thef wasn't set. I'll make that correction and see if it improves anything.

Quote:
Originally Posted by grail
The second script does but then I am back to my first question as the assignment is based on 'item' being populated.

Last edited by L_Carver; 02-06-2018 at 03:37 AM.
 
Old 02-06-2018, 04:56 AM   #6
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
I made the corrections and they worked. Marking thread as solved.
 
  


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
[SOLVED] BASH Script String Manipulation - not working in script. BW-userx Programming 14 05-22-2017 01:31 AM
[SOLVED] Script not working in cron but working fine manually jasperux Linux - Newbie 2 07-04-2012 11:28 PM
Could you help me get a script working? seabro Linux - Newbie 5 03-26-2012 03:22 AM
[SOLVED] My script is not working right kenny53067 Linux - Newbie 5 07-24-2011 01:08 AM
Crontab is not working, the script is working arfal SUSE / openSUSE 6 02-08-2010 08:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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