[Solved] Scripts don't run

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Pat D

[Solved] Scripts don't run

Post by Pat D »

I must have something seriously wrong with my system.

Among other things, NONE of the scripts on this topic work for me. viewtopic.php?f=213&t=77483

I've copied/pasted, set the exec bit, as instructed here and elsewhere. viewtopic.php?f=47&t=266311&p=1448150#p1448150

Absolutely nothing happens. More strange stuff here: viewtopic.php?f=157&t=266144&p=1448172#p1448172

I'm tired of having to re-install when stuff doesn't work and I can't get it fixed with help from multiple sources. Needing some encouragement here lest I just dump Mint and try Fedora or something.... :? :cry:
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
WharfRat

Re: Scripts don't run

Post by WharfRat »

Did you chmod it executable :?:

If you're in a folder that's not in the PATH then precede the script with ./ as in ./script
Pat D

Re: Scripts don't run

Post by Pat D »

Yes, I've done that.
I've done everything suggested.
Frustration is maxing out.
(An alternative to system problems is user problems, of course, but I don't really want to end up there.)
WharfRat

Re: Scripts don't run

Post by WharfRat »

Can you provide a listing of the script with ls -lh scriptname
Pat D

Re: Scripts don't run

Post by Pat D »

Code: Select all

@MainBox ~ $ ls -lh Script-Starter.sh
-rwxrwxrwx 1 devlin devlin 474 Mar 24 13:51 Script-Starter.sh
Is that what you wanted?
WharfRat

Re: Scripts don't run

Post by WharfRat »

Pat D wrote: Sat Mar 24, 2018 3:05 pm

Code: Select all

@MainBox ~ $ ls -lh Script-Starter.sh
-rwxrwxrwx 1 devlin devlin 474 Mar 24 13:51 Script-Starter.sh
Is that what you wanted?
Exactly - did you try ./Script-Starter.sh in the terminal :?:

What does cat ~/Script-Starter.sh return :?:
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Scripts don't run

Post by Flemur »

Pat D wrote: Sat Mar 24, 2018 3:05 pmIs that what you wanted?
How about also

Code: Select all

cat Script-Starter.sh
sh Script-Starter.sh
[and post the output of it - the error message]
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Pat D

Re: Scripts don't run

Post by Pat D »

Here you go - the script was copied and pasted from the bash sticky:

Code: Select all

devlin@MainBox ~ $ cat Script-Starter.sh
#!/bin/bash
# Purpose:	Inserts #!/bin/bash into a file and makes it executable
# Usage: 	scriptname /path/to/file.sh
# Author: 	JJ/Habitual
# Date: 	Tue Jul 19, 2011
# Version: 	1311133977
# Disclaimer:	Use it, abuse it, just don't lose it.
MINPARAMS=1

if [ -n "$1" ]
then
echo "#!/bin/bash" > $1
chmod 700 "$1"
echo File $1 is now an executable and ready to be edited.
fi 

if [ $# -lt "$MINPARAMS" ]
then
  echo Usage: `pwd`/`basename $0` /path/to/script.sh
fi  
exit 0

devlin@MainBox ~ $ sh Script-Starter.sh
Usage: /home/devlin/Script-Starter.sh /path/to/script.sh
devlin@MainBox ~ $ 
WharfRat

Re: Scripts don't run

Post by WharfRat »

Enter ./Script-Starter.sh test_script

Then paste back cat test_script
Pat D

Re: Scripts don't run

Post by Pat D »

Code: Select all

devlin@MainBox ~ $ ./Script-Starter.sh test_script
File test_script is now an executable and ready to be edited.
devlin@MainBox ~ $ cat test_script
#!/bin/bash
devlin@MainBox ~ $ 
Seems to have worked, this time.
But I had just reverted the kernel back to 4.4 as per Pjotr in viewtopic.php?p=1448266#p1448266
WharfRat

Re: Scripts don't run

Post by WharfRat »

If you look at your output

Code: Select all

devlin@MainBox ~ $ sh Script-Starter.sh
Usage: /home/devlin/Script-Starter.sh /path/to/script.sh
devlin@MainBox ~ $ 
It ran because it gave the message from this segment of the script

Code: Select all

if [ $# -lt "$MINPARAMS" ]
then
  echo Usage: `pwd`/`basename $0` /path/to/script.sh
fi  
exit 0
User avatar
Flemur
Level 20
Level 20
Posts: 10096
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Scripts don't run

Post by Flemur »

WharfRat wrote: Sat Mar 24, 2018 3:30 pmIt ran because it gave the message from this segment of the script
OP, the script did the right thing the 2nd time because you passed it the parameter it wanted.
That "if [ $# -lt "$MINPARAMS" ]" in the script said "if number of passed params less than 1" then give the error.
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Pat D

Re: Scripts don't run

Post by Pat D »

OK.
I changed the kernel tp 4.4.0-116 as Pjotr said, and now all the scripts I was trying to learn with are working. Thanking you loads, sir.
Flemur, WharfRat, with you're explanations I might be starting to get a handle on bash scripting. :D :D

(It's hard to learn to do things when your system seems to conspiring to mess things up, lol)
Locked

Return to “Scripts & Bash”