correct this script

Clash Royale CLAN TAG#URR8PPP
up vote
-3
down vote
favorite
I am having a problem with this script
#!/bin/bash
echo âÂÂEnter option âÂÂ
echo âÂÂ1 PICâÂÂ
echo âÂÂ2 ICONâÂÂ
read $answer
echo
if [[$answer == 1 ]] ; then
rename 's/^.*([0-9]3.jpg)$/ICON$1/' *.jpg ;
echo âÂÂdoneâÂÂ
elif
if [[$answer == 2 ]] ; then
rename 's/^.*([0-9]3.jpg)$/PIC$1/' *.jpg ;
echo âÂÂdoneâÂÂ
else
echo âÂÂErrorâÂÂ
fi
done
bash shell-script
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
 |Â
show 4 more comments
up vote
-3
down vote
favorite
I am having a problem with this script
#!/bin/bash
echo âÂÂEnter option âÂÂ
echo âÂÂ1 PICâÂÂ
echo âÂÂ2 ICONâÂÂ
read $answer
echo
if [[$answer == 1 ]] ; then
rename 's/^.*([0-9]3.jpg)$/ICON$1/' *.jpg ;
echo âÂÂdoneâÂÂ
elif
if [[$answer == 2 ]] ; then
rename 's/^.*([0-9]3.jpg)$/PIC$1/' *.jpg ;
echo âÂÂdoneâÂÂ
else
echo âÂÂErrorâÂÂ
fi
done
bash shell-script
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
2
Off-topic (typo):[[must be followed by a space. Double quotes should be"not typographical double quotes (âÂÂ...âÂÂ). When usingreadthe variable name should be used without$. Also, you don't mention what errors you are getting. See shellcheck.net
â Kusalananda
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago
 |Â
show 4 more comments
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I am having a problem with this script
#!/bin/bash
echo âÂÂEnter option âÂÂ
echo âÂÂ1 PICâÂÂ
echo âÂÂ2 ICONâÂÂ
read $answer
echo
if [[$answer == 1 ]] ; then
rename 's/^.*([0-9]3.jpg)$/ICON$1/' *.jpg ;
echo âÂÂdoneâÂÂ
elif
if [[$answer == 2 ]] ; then
rename 's/^.*([0-9]3.jpg)$/PIC$1/' *.jpg ;
echo âÂÂdoneâÂÂ
else
echo âÂÂErrorâÂÂ
fi
done
bash shell-script
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am having a problem with this script
#!/bin/bash
echo âÂÂEnter option âÂÂ
echo âÂÂ1 PICâÂÂ
echo âÂÂ2 ICONâÂÂ
read $answer
echo
if [[$answer == 1 ]] ; then
rename 's/^.*([0-9]3.jpg)$/ICON$1/' *.jpg ;
echo âÂÂdoneâÂÂ
elif
if [[$answer == 2 ]] ; then
rename 's/^.*([0-9]3.jpg)$/PIC$1/' *.jpg ;
echo âÂÂdoneâÂÂ
else
echo âÂÂErrorâÂÂ
fi
done
bash shell-script
bash shell-script
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 mins ago
Rui F Ribeiro
37.6k1475119
37.6k1475119
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago
Suh Fru Kieran Claver
11
11
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Suh Fru Kieran Claver is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
2
Off-topic (typo):[[must be followed by a space. Double quotes should be"not typographical double quotes (âÂÂ...âÂÂ). When usingreadthe variable name should be used without$. Also, you don't mention what errors you are getting. See shellcheck.net
â Kusalananda
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago
 |Â
show 4 more comments
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
2
Off-topic (typo):[[must be followed by a space. Double quotes should be"not typographical double quotes (âÂÂ...âÂÂ). When usingreadthe variable name should be used without$. Also, you don't mention what errors you are getting. See shellcheck.net
â Kusalananda
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
2
2
Off-topic (typo):
[[ must be followed by a space. Double quotes should be " not typographical double quotes (âÂÂ...âÂÂ). When using read the variable name should be used without $. Also, you don't mention what errors you are getting. See shellcheck.netâ Kusalananda
2 hours ago
Off-topic (typo):
[[ must be followed by a space. Double quotes should be " not typographical double quotes (âÂÂ...âÂÂ). When using read the variable name should be used without $. Also, you don't mention what errors you are getting. See shellcheck.netâ Kusalananda
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago
 |Â
show 4 more comments
2 Answers
2
active
oldest
votes
up vote
0
down vote
I think you want this. The list of the problems in your original script would be longer than the script itself.
#!/bin/bash
echo "Enter option"
echo "1 PIC"
echo "2 ICON"
read answer
echo
if [ "$answer" == 1 ]
then
ext=ICON
elif [ "$answer" == 2 ]
then
ext=PIC
else
echo "Error"
exit 1
fi
ls|grep -i .jpg$|while read i
do
mv -vf "$i" "$i%.*"."$ext"
done
echo "done"
I don't think the original script replaces the suffix, looks more like it renameswhatever123.jpgtoPIC123.jpg.
â nohillside
1 hour ago
add a comment |Â
up vote
0
down vote
To replace all but the last three digits and the filename suffix of all JPEG files in the current directory with either the word PIC or ICON, you may do the following (this interactively asks for the prefix to use):
#!/bin/bash
echo 'Please select prefix:' >&2
select prefix in 'ICON' 'PIC'; do
case $REPLY in
1) break ;;
2) break ;;
*) echo 'Try again' >&2
esac
done
rename 's/.*([0-9][0-9][0-9].jpg)/'"$prefix"'$1/' *[0-9][0-9][0-9].jpg
echo 'Done' >&2
I've chosen to use select as this produces a nice looking menu of the available options. I'm also applying the rename command only to the files that I know can be renamed (there may be other JPEG files in the directory that does not have the three digits, for example). All output from this script is strictly user interaction, so I'm doing this on the standard error stream (with >&2).
The issues with your original script are
[[must be followed by a space.- Double quotes are
"...", notâÂÂ...âÂÂ. - The
readutility takes a variable name, not a value. - There is a dangling
doneat the end of the code. elifexpects a test (not anif).
A suggestion would be to run you scripts through a syntax checker, such as the one available online at https://www.shellcheck.net/
Also, when asking questions like these, it is quite important to include the exact error message produced by the script, and also to mention what it is that you actually want to do (so that we don't have to reverse-engineer your code). See e.g. Jeff's excellent Meta question-and-answer about asking well received questions.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think you want this. The list of the problems in your original script would be longer than the script itself.
#!/bin/bash
echo "Enter option"
echo "1 PIC"
echo "2 ICON"
read answer
echo
if [ "$answer" == 1 ]
then
ext=ICON
elif [ "$answer" == 2 ]
then
ext=PIC
else
echo "Error"
exit 1
fi
ls|grep -i .jpg$|while read i
do
mv -vf "$i" "$i%.*"."$ext"
done
echo "done"
I don't think the original script replaces the suffix, looks more like it renameswhatever123.jpgtoPIC123.jpg.
â nohillside
1 hour ago
add a comment |Â
up vote
0
down vote
I think you want this. The list of the problems in your original script would be longer than the script itself.
#!/bin/bash
echo "Enter option"
echo "1 PIC"
echo "2 ICON"
read answer
echo
if [ "$answer" == 1 ]
then
ext=ICON
elif [ "$answer" == 2 ]
then
ext=PIC
else
echo "Error"
exit 1
fi
ls|grep -i .jpg$|while read i
do
mv -vf "$i" "$i%.*"."$ext"
done
echo "done"
I don't think the original script replaces the suffix, looks more like it renameswhatever123.jpgtoPIC123.jpg.
â nohillside
1 hour ago
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I think you want this. The list of the problems in your original script would be longer than the script itself.
#!/bin/bash
echo "Enter option"
echo "1 PIC"
echo "2 ICON"
read answer
echo
if [ "$answer" == 1 ]
then
ext=ICON
elif [ "$answer" == 2 ]
then
ext=PIC
else
echo "Error"
exit 1
fi
ls|grep -i .jpg$|while read i
do
mv -vf "$i" "$i%.*"."$ext"
done
echo "done"
I think you want this. The list of the problems in your original script would be longer than the script itself.
#!/bin/bash
echo "Enter option"
echo "1 PIC"
echo "2 ICON"
read answer
echo
if [ "$answer" == 1 ]
then
ext=ICON
elif [ "$answer" == 2 ]
then
ext=PIC
else
echo "Error"
exit 1
fi
ls|grep -i .jpg$|while read i
do
mv -vf "$i" "$i%.*"."$ext"
done
echo "done"
answered 2 hours ago
peterh
4,07092856
4,07092856
I don't think the original script replaces the suffix, looks more like it renameswhatever123.jpgtoPIC123.jpg.
â nohillside
1 hour ago
add a comment |Â
I don't think the original script replaces the suffix, looks more like it renameswhatever123.jpgtoPIC123.jpg.
â nohillside
1 hour ago
I don't think the original script replaces the suffix, looks more like it renames
whatever123.jpg to PIC123.jpg.â nohillside
1 hour ago
I don't think the original script replaces the suffix, looks more like it renames
whatever123.jpg to PIC123.jpg.â nohillside
1 hour ago
add a comment |Â
up vote
0
down vote
To replace all but the last three digits and the filename suffix of all JPEG files in the current directory with either the word PIC or ICON, you may do the following (this interactively asks for the prefix to use):
#!/bin/bash
echo 'Please select prefix:' >&2
select prefix in 'ICON' 'PIC'; do
case $REPLY in
1) break ;;
2) break ;;
*) echo 'Try again' >&2
esac
done
rename 's/.*([0-9][0-9][0-9].jpg)/'"$prefix"'$1/' *[0-9][0-9][0-9].jpg
echo 'Done' >&2
I've chosen to use select as this produces a nice looking menu of the available options. I'm also applying the rename command only to the files that I know can be renamed (there may be other JPEG files in the directory that does not have the three digits, for example). All output from this script is strictly user interaction, so I'm doing this on the standard error stream (with >&2).
The issues with your original script are
[[must be followed by a space.- Double quotes are
"...", notâÂÂ...âÂÂ. - The
readutility takes a variable name, not a value. - There is a dangling
doneat the end of the code. elifexpects a test (not anif).
A suggestion would be to run you scripts through a syntax checker, such as the one available online at https://www.shellcheck.net/
Also, when asking questions like these, it is quite important to include the exact error message produced by the script, and also to mention what it is that you actually want to do (so that we don't have to reverse-engineer your code). See e.g. Jeff's excellent Meta question-and-answer about asking well received questions.
add a comment |Â
up vote
0
down vote
To replace all but the last three digits and the filename suffix of all JPEG files in the current directory with either the word PIC or ICON, you may do the following (this interactively asks for the prefix to use):
#!/bin/bash
echo 'Please select prefix:' >&2
select prefix in 'ICON' 'PIC'; do
case $REPLY in
1) break ;;
2) break ;;
*) echo 'Try again' >&2
esac
done
rename 's/.*([0-9][0-9][0-9].jpg)/'"$prefix"'$1/' *[0-9][0-9][0-9].jpg
echo 'Done' >&2
I've chosen to use select as this produces a nice looking menu of the available options. I'm also applying the rename command only to the files that I know can be renamed (there may be other JPEG files in the directory that does not have the three digits, for example). All output from this script is strictly user interaction, so I'm doing this on the standard error stream (with >&2).
The issues with your original script are
[[must be followed by a space.- Double quotes are
"...", notâÂÂ...âÂÂ. - The
readutility takes a variable name, not a value. - There is a dangling
doneat the end of the code. elifexpects a test (not anif).
A suggestion would be to run you scripts through a syntax checker, such as the one available online at https://www.shellcheck.net/
Also, when asking questions like these, it is quite important to include the exact error message produced by the script, and also to mention what it is that you actually want to do (so that we don't have to reverse-engineer your code). See e.g. Jeff's excellent Meta question-and-answer about asking well received questions.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To replace all but the last three digits and the filename suffix of all JPEG files in the current directory with either the word PIC or ICON, you may do the following (this interactively asks for the prefix to use):
#!/bin/bash
echo 'Please select prefix:' >&2
select prefix in 'ICON' 'PIC'; do
case $REPLY in
1) break ;;
2) break ;;
*) echo 'Try again' >&2
esac
done
rename 's/.*([0-9][0-9][0-9].jpg)/'"$prefix"'$1/' *[0-9][0-9][0-9].jpg
echo 'Done' >&2
I've chosen to use select as this produces a nice looking menu of the available options. I'm also applying the rename command only to the files that I know can be renamed (there may be other JPEG files in the directory that does not have the three digits, for example). All output from this script is strictly user interaction, so I'm doing this on the standard error stream (with >&2).
The issues with your original script are
[[must be followed by a space.- Double quotes are
"...", notâÂÂ...âÂÂ. - The
readutility takes a variable name, not a value. - There is a dangling
doneat the end of the code. elifexpects a test (not anif).
A suggestion would be to run you scripts through a syntax checker, such as the one available online at https://www.shellcheck.net/
Also, when asking questions like these, it is quite important to include the exact error message produced by the script, and also to mention what it is that you actually want to do (so that we don't have to reverse-engineer your code). See e.g. Jeff's excellent Meta question-and-answer about asking well received questions.
To replace all but the last three digits and the filename suffix of all JPEG files in the current directory with either the word PIC or ICON, you may do the following (this interactively asks for the prefix to use):
#!/bin/bash
echo 'Please select prefix:' >&2
select prefix in 'ICON' 'PIC'; do
case $REPLY in
1) break ;;
2) break ;;
*) echo 'Try again' >&2
esac
done
rename 's/.*([0-9][0-9][0-9].jpg)/'"$prefix"'$1/' *[0-9][0-9][0-9].jpg
echo 'Done' >&2
I've chosen to use select as this produces a nice looking menu of the available options. I'm also applying the rename command only to the files that I know can be renamed (there may be other JPEG files in the directory that does not have the three digits, for example). All output from this script is strictly user interaction, so I'm doing this on the standard error stream (with >&2).
The issues with your original script are
[[must be followed by a space.- Double quotes are
"...", notâÂÂ...âÂÂ. - The
readutility takes a variable name, not a value. - There is a dangling
doneat the end of the code. elifexpects a test (not anif).
A suggestion would be to run you scripts through a syntax checker, such as the one available online at https://www.shellcheck.net/
Also, when asking questions like these, it is quite important to include the exact error message produced by the script, and also to mention what it is that you actually want to do (so that we don't have to reverse-engineer your code). See e.g. Jeff's excellent Meta question-and-answer about asking well received questions.
edited 22 mins ago
answered 39 mins ago
Kusalananda
111k15216343
111k15216343
add a comment |Â
add a comment |Â
Suh Fru Kieran Claver is a new contributor. Be nice, and check out our Code of Conduct.
Suh Fru Kieran Claver is a new contributor. Be nice, and check out our Code of Conduct.
Suh Fru Kieran Claver is a new contributor. Be nice, and check out our Code of Conduct.
Suh Fru Kieran Claver is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478095%2fcorrect-this-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Give more info: what you want, what are the results. Or your question will be closed!
â peterh
2 hours ago
It is a script that renames images in a file to either PIC or ICON with an option menu with it . Wen ever I run the script it keeps telling me error
â Suh Fru Kieran Claver
2 hours ago
2
Off-topic (typo):
[[must be followed by a space. Double quotes should be"not typographical double quotes (âÂÂ...âÂÂ). When usingreadthe variable name should be used without$. Also, you don't mention what errors you are getting. See shellcheck.netâ Kusalananda
2 hours ago
The script doesnâÂÂt execute and it skips down to the last part were it says echo Error
â Suh Fru Kieran Claver
2 hours ago
The original version of your script was so buggy, that I couldn't even correctly indent it. Its current version might be a better option for bugfixing.
â peterh
2 hours ago