Why won't this script work? [Solved]
Why won't this script work?
I'm on MX23/kde, trying to get a script to work with no luck.
System Info:
Processes: 357 Uptime: 14h 13m wakeups: 1 Memory: 15.52 GiB used: 8.07 GiB (52.0%) Init: SysVinit
v: 3.06 runlevel: 5 default: graphical tool: systemctl Compilers: gcc: 12.2.0 alt: 12
Client: shell wrapper v: 5.2.15-release inxi: 3.3.26
Bash location:
$ whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
Attempt to run script:
paul@mx:~
$ls r*
remove.sh
$ ./remove.sh
bash: ./remove.sh: cannot execute: required file not found
If I click on remove.sh in Dolphin, I get:
execvp: No such file or directory
The script is marked executable.
The script itself:
_______________
#!/usr/bin/bash
#
echo "Hello World"
ls
_______________
I've also tried it with the shebang:
#!/bin/bash
I was originally trying to use the script to delete a file. I was then going to schedule it as a job. But when it wouldn't work I kept simplifying the script until I was sure it was some kind of system/script problem, not a command within the script.
Thanks for any guidance.
System Info:
Processes: 357 Uptime: 14h 13m wakeups: 1 Memory: 15.52 GiB used: 8.07 GiB (52.0%) Init: SysVinit
v: 3.06 runlevel: 5 default: graphical tool: systemctl Compilers: gcc: 12.2.0 alt: 12
Client: shell wrapper v: 5.2.15-release inxi: 3.3.26
Bash location:
$ whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
Attempt to run script:
paul@mx:~
$ls r*
remove.sh
$ ./remove.sh
bash: ./remove.sh: cannot execute: required file not found
If I click on remove.sh in Dolphin, I get:
execvp: No such file or directory
The script is marked executable.
The script itself:
_______________
#!/usr/bin/bash
#
echo "Hello World"
ls
_______________
I've also tried it with the shebang:
#!/bin/bash
I was originally trying to use the script to delete a file. I was then going to schedule it as a job. But when it wouldn't work I kept simplifying the script until I was sure it was some kind of system/script problem, not a command within the script.
Thanks for any guidance.
MX-19-KDE x64, on Ryzen 5, 16GB RAM, SSD. Nvidia graphics.
Re: Why won't this script work?
I do not have the time right now but maybe this refresher will help you.
https://phoenixnap.com/kb/write-bash-script
https://phoenixnap.com/kb/write-bash-script
It is easier to fight for one's principles then to live up to them.
Re: Why won't this script work?
Thanks, I think I have those bases covered.
Also, when I use the shebang,
#!/usr/bin/env bash
I get the result:
$ ./remove.sh
/usr/bin/env: ‘bash\r’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
which I have no clue about.
Also, when I use the shebang,
#!/usr/bin/env bash
I get the result:
$ ./remove.sh
/usr/bin/env: ‘bash\r’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
which I have no clue about.
MX-19-KDE x64, on Ryzen 5, 16GB RAM, SSD. Nvidia graphics.
Re: Why won't this script work?
Not sure what is going on with that script... this works perfectly in my KDE tester (marked executable )
called from terminal using
sh test.sh
test.sh is
called from terminal using
sh test.sh
test.sh is
Code: Select all
#!/bin/bash
echo "hello world"
ls
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!
Re: Why won't this script work?
Thanks.
When I entered
from the directory that script lies in, it did execute. I did not even have to precede it with "./", as in
which I thought was necessary. So maybe I'd misunderstood how to call scripts from the command line?
I'm confused at what's going on. Clicking on the script in Dolphin still brings an error. I thought scripts could be invoked through the file manager?
When I entered
Code: Select all
sh remove.sh
Code: Select all
sh ./remove.sh
I'm confused at what's going on. Clicking on the script in Dolphin still brings an error. I thought scripts could be invoked through the file manager?
MX-19-KDE x64, on Ryzen 5, 16GB RAM, SSD. Nvidia graphics.
Re: Why won't this script work?
You have no posted the script-file itself, but rather a textual copy/paste,paul1149 wrote: Sat Dec 02, 2023 11:32 pm I'm on MX23/kde, trying to get a script to work with no luck.
System Info:
Processes: 357 Uptime: 14h 13m wakeups: 1 Memory: 15.52 GiB used: 8.07 GiB (52.0%) Init: SysVinit
v: 3.06 runlevel: 5 default: graphical tool: systemctl Compilers: gcc: 12.2.0 alt: 12
Client: shell wrapper v: 5.2.15-release inxi: 3.3.26
Bash location:
$ whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz
Attempt to run script:
paul@mx:~
$ls r*
remove.sh
$ ./remove.sh
bash: ./remove.sh: cannot execute: required file not found
If I click on remove.sh in Dolphin, I get:
execvp: No such file or directory
The script is marked executable.
The script itself:
_______________
#!/usr/bin/bash
#
echo "Hello World"
ls
_______________
I've also tried it with the shebang:
#!/bin/bash
I was originally trying to use the script to delete a file. I was then going to schedule it as a job. But when it wouldn't work I kept simplifying the script until I was sure it was some kind of system/script problem, not a command within the script.
Thanks for any guidance.
where the "failure" within the script file is not visible anymore.
May be this: Open terminal (konsole) with the folder the script is located and post the text shown
from this command:
Code: Select all
cat -v remove.sh
Re: Why won't this script work?
I use the xfce terminal, just to be clear, but here is the output.
Code: Select all
paul@mx:~
$ cat -v remove.sh
#! /usr/bin/bash^M
#^M
echo "Hello World"^M
ls^M
paul@mx:~
MX-19-KDE x64, on Ryzen 5, 16GB RAM, SSD. Nvidia graphics.
Re: Why won't this script work? [Solved]
Which tells: It tries to find the executable "bash^M", which does not exist,paul1149 wrote: Sun Dec 03, 2023 12:05 pm I use the xfce terminal, just to be clear, but here is the output.
Code: Select all
paul@mx:~ $ cat -v remove.sh #! /usr/bin/bash^M #^M echo "Hello World"^M ls^M paul@mx:~
b/c in linux text-files,and script files are line terminated with linefeed.
The "^M" as shown represents a carriage return character,
b/c other OS like Dos/Windows do use two characters for line endings carriage return+line feed.
To make the script created by a windows supporting text-editor,
you may consider to remove the carriage return,
e.g. this way:
Code: Select all
sed -i 's/\r//' remove.sh
Re: Why won't this script work?
Wow, that's all it was. I switched the file to UNIX endings, and it worked not only in the command line, but through Dolphin. I suspected it had to be something basic, but this never occurred to me.
Thanks much, mystery solved!
Thanks much, mystery solved!
MX-19-KDE x64, on Ryzen 5, 16GB RAM, SSD. Nvidia graphics.
- DukeComposed
- Posts: 1507
- Joined: Thu Mar 16, 2023 1:57 pm
Re: Why won't this script work?
As fehlix points out, "\r" in the output at the end of a line is a dead giveaway that this script was written on a Windows machine and copied to a Linux machine. Another way to clean a text file or script to ensure it has Linux-friendly line endings is to run "col < filename > new_filename". The col program was written explicitly to fix line endings, and can also convert between tabs and spaces when prompted.paul1149 wrote: Sun Dec 03, 2023 11:06 am Also, when I use the shebang,
#!/usr/bin/env bash
I get the result:
$ ./remove.sh
/usr/bin/env: ‘bash\r’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
which I have no clue about.