[Solved] Scripts don't run

Forum rules
Before you post please read how to get help
Post Reply
Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

[Solved] Scripts don't run

Post by Pat D » Sat Mar 24, 2018 2:09 pm

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 Pat D on Sat Mar 24, 2018 4:47 pm, edited 1 time in total.

User avatar
WharfRat
Level 20
Level 20
Posts: 11834
Joined: Thu Apr 07, 2011 8:15 pm

Re: Scripts don't run

Post by WharfRat » Sat Mar 24, 2018 2:12 pm

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
ImageImage

Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

Re: Scripts don't run

Post by Pat D » Sat Mar 24, 2018 2:25 pm

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.)

User avatar
WharfRat
Level 20
Level 20
Posts: 11834
Joined: Thu Apr 07, 2011 8:15 pm

Re: Scripts don't run

Post by WharfRat » Sat Mar 24, 2018 2:41 pm

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

Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

Re: Scripts don't run

Post by Pat D » 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?

User avatar
WharfRat
Level 20
Level 20
Posts: 11834
Joined: Thu Apr 07, 2011 8:15 pm

Re: Scripts don't run

Post by WharfRat » Sat Mar 24, 2018 3:11 pm

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 :?:
ImageImage

User avatar
Flemur
Level 16
Level 16
Posts: 6283
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Scripts don't run

Post by Flemur » Sat Mar 24, 2018 3:12 pm

Pat D wrote:
Sat Mar 24, 2018 3:05 pm
Is 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?
Mint 18.3 Xfce/fluxbox/pulse-less
Xubuntu 17.10/fluxbox/pulse-less

Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

Re: Scripts don't run

Post by Pat D » Sat Mar 24, 2018 3:19 pm

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 ~ $ 

User avatar
WharfRat
Level 20
Level 20
Posts: 11834
Joined: Thu Apr 07, 2011 8:15 pm

Re: Scripts don't run

Post by WharfRat » Sat Mar 24, 2018 3:24 pm

Enter ./Script-Starter.sh test_script

Then paste back cat test_script
ImageImage

Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

Re: Scripts don't run

Post by Pat D » Sat Mar 24, 2018 3:28 pm

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

User avatar
WharfRat
Level 20
Level 20
Posts: 11834
Joined: Thu Apr 07, 2011 8:15 pm

Re: Scripts don't run

Post by WharfRat » Sat Mar 24, 2018 3:30 pm

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
ImageImage

User avatar
Flemur
Level 16
Level 16
Posts: 6283
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: Scripts don't run

Post by Flemur » Sat Mar 24, 2018 4:00 pm

WharfRat wrote:
Sat Mar 24, 2018 3:30 pm
It 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?
Mint 18.3 Xfce/fluxbox/pulse-less
Xubuntu 17.10/fluxbox/pulse-less

Pat D
Level 4
Level 4
Posts: 360
Joined: Thu Jul 14, 2016 2:31 pm

Re: Scripts don't run

Post by Pat D » Sat Mar 24, 2018 4:46 pm

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)

Post Reply

Return to “Scripts & Bash”