ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/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.
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.
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.
Yes, I see where 'thef' stays empty (mistake now remedied)
Quote:
Originally Posted by grail
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.