Read string block as multiple variables ubuntu
up vote
1
down vote
favorite
I have a script to copy permissions which works fine, being the interesting line this one:
...
bash commands.sh $PAM_USER "medium" /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed} /usr/bin/{vim,touch,java,python,gcc,awk,make}
...
commands.sh has a loop which reads through all permissions listed and copies them to a specified directory.
Problem comes when I try to do the same thing reading the permissions from a config file.
My config file contains the following:
MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
MEDIUM_PERMISSIONS_USR_BIN=/usr/bin/{vim,touch,java,python,gcc,awk,make}
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
Note: the last two configurations are for something different, for now I'm trying to read the first two lines properly.
I add the config file to the previous script and try to execute the following:
source /etc/users/config.cfg
...
bash commands.sh $PAM_USER "medium" $MEDIUM_PERMISSIONS_BIN $MEDIUM_PERMISSIONS_USR_BIN
...
The problem is that the loop reads it as such:
loop: /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
loop: /usr/bin/{vim,touch,java,python,gcc,awk,make}
when previously it used to read it as /bin/ls, /bin/rm, /bin/rm and so on, hence the loop working with the first version as it is able to find those commands, but not on the second version sisnce the output specified previously is incorrect.
I've read through the sed and awk commands but I'm quite new to this and can't get them to work.
How can I read the permissions from my config file as if I was introducing them directly like in the first version?
Thanks
edit: commands.sh code:
#!/bin/bash
CHROOT="/users/$2/$1"
if [ ! -d "$CHROOT/home/$1" ]; then
mkdir -p "$CHROOT/home/$1"
fi
for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq )
do
cp -v --parents $i $CHROOT
done
#ARCH amd64
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT
fi
#ARCH i386
if [ -f /lib/ld-linux.so.2 ]; then
cp --parents /lib/ld-linux.so.2 /$CHROOT
fi
clear
cd
Comment: I removed all the debugging echoes. This code is pretty much a copy from a code you can find here: https://linuxconfig.org/how-to-automatically-chroot-jail-selected-ssh-user-logins
bash scripting
New contributor
add a comment |
up vote
1
down vote
favorite
I have a script to copy permissions which works fine, being the interesting line this one:
...
bash commands.sh $PAM_USER "medium" /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed} /usr/bin/{vim,touch,java,python,gcc,awk,make}
...
commands.sh has a loop which reads through all permissions listed and copies them to a specified directory.
Problem comes when I try to do the same thing reading the permissions from a config file.
My config file contains the following:
MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
MEDIUM_PERMISSIONS_USR_BIN=/usr/bin/{vim,touch,java,python,gcc,awk,make}
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
Note: the last two configurations are for something different, for now I'm trying to read the first two lines properly.
I add the config file to the previous script and try to execute the following:
source /etc/users/config.cfg
...
bash commands.sh $PAM_USER "medium" $MEDIUM_PERMISSIONS_BIN $MEDIUM_PERMISSIONS_USR_BIN
...
The problem is that the loop reads it as such:
loop: /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
loop: /usr/bin/{vim,touch,java,python,gcc,awk,make}
when previously it used to read it as /bin/ls, /bin/rm, /bin/rm and so on, hence the loop working with the first version as it is able to find those commands, but not on the second version sisnce the output specified previously is incorrect.
I've read through the sed and awk commands but I'm quite new to this and can't get them to work.
How can I read the permissions from my config file as if I was introducing them directly like in the first version?
Thanks
edit: commands.sh code:
#!/bin/bash
CHROOT="/users/$2/$1"
if [ ! -d "$CHROOT/home/$1" ]; then
mkdir -p "$CHROOT/home/$1"
fi
for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq )
do
cp -v --parents $i $CHROOT
done
#ARCH amd64
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT
fi
#ARCH i386
if [ -f /lib/ld-linux.so.2 ]; then
cp --parents /lib/ld-linux.so.2 /$CHROOT
fi
clear
cd
Comment: I removed all the debugging echoes. This code is pretty much a copy from a code you can find here: https://linuxconfig.org/how-to-automatically-chroot-jail-selected-ssh-user-logins
bash scripting
New contributor
1
Please edit your question and show us thecommands.sh
script. We need to see the code to understand how it reads whatever it reads.
– terdon♦
Dec 3 at 11:22
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a script to copy permissions which works fine, being the interesting line this one:
...
bash commands.sh $PAM_USER "medium" /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed} /usr/bin/{vim,touch,java,python,gcc,awk,make}
...
commands.sh has a loop which reads through all permissions listed and copies them to a specified directory.
Problem comes when I try to do the same thing reading the permissions from a config file.
My config file contains the following:
MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
MEDIUM_PERMISSIONS_USR_BIN=/usr/bin/{vim,touch,java,python,gcc,awk,make}
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
Note: the last two configurations are for something different, for now I'm trying to read the first two lines properly.
I add the config file to the previous script and try to execute the following:
source /etc/users/config.cfg
...
bash commands.sh $PAM_USER "medium" $MEDIUM_PERMISSIONS_BIN $MEDIUM_PERMISSIONS_USR_BIN
...
The problem is that the loop reads it as such:
loop: /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
loop: /usr/bin/{vim,touch,java,python,gcc,awk,make}
when previously it used to read it as /bin/ls, /bin/rm, /bin/rm and so on, hence the loop working with the first version as it is able to find those commands, but not on the second version sisnce the output specified previously is incorrect.
I've read through the sed and awk commands but I'm quite new to this and can't get them to work.
How can I read the permissions from my config file as if I was introducing them directly like in the first version?
Thanks
edit: commands.sh code:
#!/bin/bash
CHROOT="/users/$2/$1"
if [ ! -d "$CHROOT/home/$1" ]; then
mkdir -p "$CHROOT/home/$1"
fi
for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq )
do
cp -v --parents $i $CHROOT
done
#ARCH amd64
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT
fi
#ARCH i386
if [ -f /lib/ld-linux.so.2 ]; then
cp --parents /lib/ld-linux.so.2 /$CHROOT
fi
clear
cd
Comment: I removed all the debugging echoes. This code is pretty much a copy from a code you can find here: https://linuxconfig.org/how-to-automatically-chroot-jail-selected-ssh-user-logins
bash scripting
New contributor
I have a script to copy permissions which works fine, being the interesting line this one:
...
bash commands.sh $PAM_USER "medium" /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed} /usr/bin/{vim,touch,java,python,gcc,awk,make}
...
commands.sh has a loop which reads through all permissions listed and copies them to a specified directory.
Problem comes when I try to do the same thing reading the permissions from a config file.
My config file contains the following:
MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
MEDIUM_PERMISSIONS_USR_BIN=/usr/bin/{vim,touch,java,python,gcc,awk,make}
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
Note: the last two configurations are for something different, for now I'm trying to read the first two lines properly.
I add the config file to the previous script and try to execute the following:
source /etc/users/config.cfg
...
bash commands.sh $PAM_USER "medium" $MEDIUM_PERMISSIONS_BIN $MEDIUM_PERMISSIONS_USR_BIN
...
The problem is that the loop reads it as such:
loop: /bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
loop: /usr/bin/{vim,touch,java,python,gcc,awk,make}
when previously it used to read it as /bin/ls, /bin/rm, /bin/rm and so on, hence the loop working with the first version as it is able to find those commands, but not on the second version sisnce the output specified previously is incorrect.
I've read through the sed and awk commands but I'm quite new to this and can't get them to work.
How can I read the permissions from my config file as if I was introducing them directly like in the first version?
Thanks
edit: commands.sh code:
#!/bin/bash
CHROOT="/users/$2/$1"
if [ ! -d "$CHROOT/home/$1" ]; then
mkdir -p "$CHROOT/home/$1"
fi
for i in $( ldd $* | grep -v dynamic | cut -d " " -f 3 | sed 's/://' | sort | uniq )
do
cp -v --parents $i $CHROOT
done
#ARCH amd64
if [ -f /lib64/ld-linux-x86-64.so.2 ]; then
cp --parents /lib64/ld-linux-x86-64.so.2 /$CHROOT
fi
#ARCH i386
if [ -f /lib/ld-linux.so.2 ]; then
cp --parents /lib/ld-linux.so.2 /$CHROOT
fi
clear
cd
Comment: I removed all the debugging echoes. This code is pretty much a copy from a code you can find here: https://linuxconfig.org/how-to-automatically-chroot-jail-selected-ssh-user-logins
bash scripting
bash scripting
New contributor
New contributor
edited Dec 3 at 13:56
New contributor
asked Dec 3 at 11:13
sartox
83
83
New contributor
New contributor
1
Please edit your question and show us thecommands.sh
script. We need to see the code to understand how it reads whatever it reads.
– terdon♦
Dec 3 at 11:22
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57
add a comment |
1
Please edit your question and show us thecommands.sh
script. We need to see the code to understand how it reads whatever it reads.
– terdon♦
Dec 3 at 11:22
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57
1
1
Please edit your question and show us the
commands.sh
script. We need to see the code to understand how it reads whatever it reads.– terdon♦
Dec 3 at 11:22
Please edit your question and show us the
commands.sh
script. We need to see the code to understand how it reads whatever it reads.– terdon♦
Dec 3 at 11:22
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You are trying to define an array variable but are using the format for a string:
## This will define a string variable
$ MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
$ echo $MEDIUM_PERMISSIONS_BIN
/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
## The parentheses tell the shell this is an array
$ MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
$ echo $MEDIUM_PERMISSIONS_BIN ## the 1st element of the array
/bin/ls
$ echo ${MEDIUM_PERMISSIONS_BIN[@]} ## the entire array
/bin/ls /bin/rm /bin/bash /bin/nano /bin/mkdir /bin/kill /bin/ln /bin/ps /bin/grep /bin/sed
So just change your config file to:
MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
MEDIUM_PERMISSIONS_USR_BIN=(/usr/bin/{vim,touch,java,python,gcc,awk,make})
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
And then, in your script, use "${MEDIUM_PERMISSIONS_BIN[@]}"
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You are trying to define an array variable but are using the format for a string:
## This will define a string variable
$ MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
$ echo $MEDIUM_PERMISSIONS_BIN
/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
## The parentheses tell the shell this is an array
$ MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
$ echo $MEDIUM_PERMISSIONS_BIN ## the 1st element of the array
/bin/ls
$ echo ${MEDIUM_PERMISSIONS_BIN[@]} ## the entire array
/bin/ls /bin/rm /bin/bash /bin/nano /bin/mkdir /bin/kill /bin/ln /bin/ps /bin/grep /bin/sed
So just change your config file to:
MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
MEDIUM_PERMISSIONS_USR_BIN=(/usr/bin/{vim,touch,java,python,gcc,awk,make})
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
And then, in your script, use "${MEDIUM_PERMISSIONS_BIN[@]}"
.
add a comment |
up vote
1
down vote
accepted
You are trying to define an array variable but are using the format for a string:
## This will define a string variable
$ MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
$ echo $MEDIUM_PERMISSIONS_BIN
/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
## The parentheses tell the shell this is an array
$ MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
$ echo $MEDIUM_PERMISSIONS_BIN ## the 1st element of the array
/bin/ls
$ echo ${MEDIUM_PERMISSIONS_BIN[@]} ## the entire array
/bin/ls /bin/rm /bin/bash /bin/nano /bin/mkdir /bin/kill /bin/ln /bin/ps /bin/grep /bin/sed
So just change your config file to:
MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
MEDIUM_PERMISSIONS_USR_BIN=(/usr/bin/{vim,touch,java,python,gcc,awk,make})
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
And then, in your script, use "${MEDIUM_PERMISSIONS_BIN[@]}"
.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You are trying to define an array variable but are using the format for a string:
## This will define a string variable
$ MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
$ echo $MEDIUM_PERMISSIONS_BIN
/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
## The parentheses tell the shell this is an array
$ MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
$ echo $MEDIUM_PERMISSIONS_BIN ## the 1st element of the array
/bin/ls
$ echo ${MEDIUM_PERMISSIONS_BIN[@]} ## the entire array
/bin/ls /bin/rm /bin/bash /bin/nano /bin/mkdir /bin/kill /bin/ln /bin/ps /bin/grep /bin/sed
So just change your config file to:
MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
MEDIUM_PERMISSIONS_USR_BIN=(/usr/bin/{vim,touch,java,python,gcc,awk,make})
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
And then, in your script, use "${MEDIUM_PERMISSIONS_BIN[@]}"
.
You are trying to define an array variable but are using the format for a string:
## This will define a string variable
$ MEDIUM_PERMISSIONS_BIN=/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
$ echo $MEDIUM_PERMISSIONS_BIN
/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed}
## The parentheses tell the shell this is an array
$ MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
$ echo $MEDIUM_PERMISSIONS_BIN ## the 1st element of the array
/bin/ls
$ echo ${MEDIUM_PERMISSIONS_BIN[@]} ## the entire array
/bin/ls /bin/rm /bin/bash /bin/nano /bin/mkdir /bin/kill /bin/ln /bin/ps /bin/grep /bin/sed
So just change your config file to:
MEDIUM_PERMISSIONS_BIN=(/bin/{ls,rm,bash,nano,mkdir,kill,ln,ps,grep,sed})
MEDIUM_PERMISSIONS_USR_BIN=(/usr/bin/{vim,touch,java,python,gcc,awk,make})
MEDIUM_ENVIROMENT_LIFESPAN=midnight
MEDIUM_PERSISTENT_HOME=true
And then, in your script, use "${MEDIUM_PERMISSIONS_BIN[@]}"
.
answered Dec 3 at 11:27
terdon♦
127k31245422
127k31245422
add a comment |
add a comment |
sartox is a new contributor. Be nice, and check out our Code of Conduct.
sartox is a new contributor. Be nice, and check out our Code of Conduct.
sartox is a new contributor. Be nice, and check out our Code of Conduct.
sartox is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485664%2fread-string-block-as-multiple-variables-ubuntu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please edit your question and show us the
commands.sh
script. We need to see the code to understand how it reads whatever it reads.– terdon♦
Dec 3 at 11:22
@terdon done. I should have included it in my original post, sorry. Anyways, your post seems to work perfectly and also explaining how it works. Much appreciated :)
– sartox
Dec 3 at 13:55
Yeah, I guessed how you were reading it after leaving the comment :)
– terdon♦
Dec 3 at 13:57