M
M
Miroslavux2019-05-16 13:22:15
linux
Miroslavux, 2019-05-16 13:22:15

How to run sh scripts in Linux?

It is necessary that the sh files be executed, "chmod +x script.sh" will not work, since you have to do it all the time, and this is the boss's computer ...
PS Linux distribution kit ALT (Russian mandriva)

Answer the question

In order to leave comments, you need to log in

6 answer(s)
S
Sanes, 2019-05-16
@Sanes

sh script.sh

S
Saboteur, 2019-05-16
@saboteur_kiev

You just need to realize that in Linux there are no file associations by extensions.
An extension for Linux is just a part of the file after the last dot, the system does not bind any actions to this.
Therefore, the only way to make .sh files executable is to set the executable flag on them via
Another option is to run bash itself, passing the file as an argument to it (because the bash binary is already executable).
bash file.sh

A
astronaut808, 2019-05-16
@astronaut808

in order not to constantly specify the interpreter in the terminal, you can make the script executable.
1. specify the interpreter in the script - specify the path to the bash interpreter after #!
it is like this by default.
you can check whereis bash
2. run the command to make it executable
3. after that you can run it just like./script.sh

B
bova, 2019-05-17
@bova8

And so
-----
$ cat ttt.sh
#!/bin/sh
echo "This is test"
$ ls -l ttt.sh
-rw-r--r-- 1 user user 32 May 17 16:26 ttt .sh
$ sh < ttt.sh
This is test

O
OFFSIDE1979, 2019-05-17
@OFFSIDE1979

Place the script on a disk with a fat32 file system.

E
Educated, 2019-05-19
@Educated

1 vim testik (or any other text editor)
2. #!/bin/bash
echo "This is test"
3.chmod a+x ./testik
cp ./testik /usr/bin/
Will run as 'testik' when in any directory!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question