Having trouble writing my first bash script - linux

ok I am writing my first bash script in ubuntu 10.04.
The file is on my desktop: /home/myuser/Desktop
The file is called hello-world
The file contains:
#!/bin/bash
echo "Hello World"
I open a command line and run:
/home/myuser/Desktop/hello-world
It tells me permition is denied. So I run it again with sudo, it asks me for my password, I type it in, hit return.
I get this output.
sudo:
/home/myuser/Desktop/hello-world:
command not found
What am I doing wrong?

Your script probably is not set to be executable. Try:
chmod u+x /home/myuser/Desktop/hello-world

If your script is called test.sh then do the following...
$ chmod +x test.sh
followed by
$ ./test.sh

chmod +x hello-world

You need to mark the script as executable. Run chmod +x hello-world to add the executable bit.

You can also do:
sh /home/myuser/Desktop/hello-world
which will execute the script without it needing to be set as executable.

Related

Is a Unix list not supported in Dockerfile?

I am changing the privileges on a few scripts before running them in the containers. I want to modify the script's permissions in one command.
This fails for the Dockerfile command:
RUN chmod +x {add, subtract}.sh
The following does work:
chmod +x *.sh
However, I do not want all the scripts in the local folder to have the execute permission.
Edit:
Here is the full Dockerfile:
FROM golang:1.12
COPY . .
RUN chmod +x {add, subtract}.sh
It fails not only because of docker, but because it is invalid sh syntax. For the shell syntax portion, you want:
chmod +x {add,subtract}.sh
Note the space is removed after the comma.
Furthermore, as per this, to allow for normal shell processing you need to modify the RUN command a little. To achieve what you want, do this:
RUN /bin/bash -c 'chmod +x /tmp/{add,subtract}.sh'
Tested with:
FROM golang:1.12
COPY add.sh /tmp
COPY subtract.sh /tmp
RUN /bin/bash -c 'chmod +x /tmp/{add,subtract}.sh'

Bash script not running , user issue

i've created a bash script batch-create-users.sh and I want execute it from the terminal, Im on the folder when the script is and I run the command
./batch-create-users.sh and I got error
the file './batch-create-users.sh' is not executable by this user
I entered as sudo -s and give the password but it doesn't help, any idea?
Give execute privilege to the file before executing.
chmod +x batch-create-users.sh

sudo: unable to excute ./blah.sh: No such file or directory

I got this error
sudo: unable to excute ./blah.sh: No such file or directory
my code is every simple
#!/bin/bash
echo "blah"
And I'm sure that I've changed the permission to "rwx". When I try sudo bash blah.sh, I will get the output. But I still cant execute the file. And I'm in debian OS.
Anyone knows why?
make it executable
sudo chmod a+x ./blah.sh
that sets the executable bit for all users just
+x
for your single user
Check in /etc/sudoers if your username is allowed to sudo.

Execute a script on startup of SUSE reboot

I'm trying to execute a script called "testing" on startup of my SUSE reboot. So I placed this simple script to '/etc/init.d'
The code is like this
#!/bin/bash
# ScriptName=testing
cat > ~/output << "EOF"
This text is generated on startup!!
EOF
After that, I execute these command
chmod +x /etc/init.d/testing
touch /etc/rc.d/rc3.d/S12testing
But after I reboot the system, nothing happened.
There must be something I missed out.
Here is the reference I searched.
chmod +x /etc/init.d/testing
touch /etc/init.d/rc.d/rc3.d/S12testing
Should not be 'touch', but a symbolic link (ln -s) to /etc/init.d/testing.
Try
cd /etc/init.d/rc.d/rc3.d
ln -s ../../testing S12testing
Hope this helps.

Really strange behavior with Linux Shell Scripts

i am really wondering why Linux (Debian Squeeze) is acting kind of crazy.
I've been trying to execute a simple test.sh script in my webapps directory:
/var/www/tomcat7/webapps/ROOT/WEB-INF/bin/
How to execute a script? Well, that would be done by entering:
EDIT: ITS NOT ABOUT WRONG (FORGOTTEN) PERMISSIONS:
chmod +x test.sh
./test.sh
which now gives me the following:
-bash: ./test.sh: No permission
test.sh is looking like this:
#!/bin/bash
echo "Hello!"
What the hek? Copying/Moving test.sh to my home directory and execute it again, which gives me:
Hello!
which is actually the output from my test.sh file. So, it doesnt work in my webapp directory but it works in home?
My researches:
Trying to execute the script with sudo rights:
When executing the script with sudo the script simply does nothing. No messages at all.
Trying to execute it via
. test.sh
It works! But why?
The volume the file is on is mounted noexec. You will need to remount it exec, but consider/research why it was mounted noexec in the first place.

Resources