Is a Unix list not supported in Dockerfile? - linux

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'

Related

My script file stopped executing when there change in user in script what should i do

My code file looks as follows
Cd testR
Mkdir bin
chmod -R 755 bin
Sudo su - inst1
cp inst1/installable/files/testR.p
...
...
So after sudo su the execution get paused please let me know what should i do
If there is no problem that your commands are executing as root, you can execute your script like this:
sudo ./yourscript
So, you don't have to switch within your shell script.

Setfacl not working correctly in dockerfile

I added setfacl command in my dockerfile put its not executed in the product image, however, when I executed manually inside the image container its working perfect
I tried using RUN command and its not working
i read before that ACL commands not preserved in the docker image so
these 3 lines are part of my Dockerfile which is Script containing the setfacl commands I want to execute
COPY script.sh .
RUN chmod +x script.sh
RUN sh script.sh
and the script contain
#!/bin/bash
setfacl -R -d -m g::rwx /var/www/html/storage/framework/views/
setfacl -R -d -m o::rw /var/www/html/storage/framework/views/
mkdir create-testdir-to-make-sure-that-script-is-executed
the test dir executed successfully, whereas the setfacl didn't make any effect cause when i create any file in the container in the views dir its not take the permisions in the setfacl

Remove ".bash_aliases" with bash script

In my .bashrc I'm using .sh script for easily configuring newly installed Debian. But while trying to
rm -f ~/.bash_aliases
wget https://raw.githubusercontent.com/.../.bash_aliases
rm -f ~/.bashrc
wget https://raw.githubusercontent.com/.../.bashrc
it's just omitting those line?
File is with permission chmod +x ./script.sh and run by sudo ./script.sh
What could possibly be wrong?
(In final code there is full link, files are being downloaded as .bashrc.1 and .bash_aliases.1)
Don't use sudo unless you have a good reason.
When you run sudo ./script.sh it runs as root, so ~ refers to root's home directory /root instead of your user's home directory.
Just run ./script.sh instead, so that it runs as you and modifies your own home directory.

How to create a custom bash command in linux

The question is about bash shell commands in ubuntu 10.04.
I have created a simple addition program in c and it works fine in my terminal.
Now I want to make this program to execute into my terminal as a command.
How can I convert a C program into a bash shell command?
How to make that command an system command like others?
yout just have to change it's owner & group root following commands
sudo chown root "file_name"
sudo chgrp root "file_name"
then give this command to change the permissions
sudo chmod 755 "file_name"
and place it in /bin with this command
sudo mv "file_name" /bin
now u can run it as a normal command.
You run your code by ./compiled-c-program
If you like to run like the other "system" program you need to add a static link to your program to one of the folder from your $PATH variable e.g.:
ln -s ~/bin/c-compiled-c-program path/to/the/program/compiled-c-program
Good luck!
I guess you want this C program to be executed by any user, as a system command. If this is your requirement, then you can add an execute permission to everyone by chmod +x <program name> and then add the program absolute path in the system define PATH environment variable.

Having trouble writing my first bash script

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.

Resources