You are not logged in.
Is this easily achieved? To illustrate, consider:
An executable script: /scratch/run.sh
#!/bin/bash
. /scratch/c.conf
echo $var
The corresponding config file /scratch/c.conf
var='hello world'
top
Upon running /scratch/run.sh not only does 'var' get defined, but top is launched even though /scratch/c.conf has octal permissions of 644. Is there a way to prevent this and only allow the parent /scratch/run.sh to read in variables but not to run an executable?
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
`source` simply executes all of the commands in a given file, so unfortunately no --- although I'd love to learn if someone could prove me wrong. How about filtering only the variable assignments, either using grep, sed, bash, or whatever and then`eval` the resulting string or output to a tmp file to later be sourced.
Offline
How about filtering only the variable assignments, either using grep, sed, bash, or whatever and then`eval` the resulting string or output to a tmp file to later be sourced.
That's easily bypassed. See the comments in:
http://wiki.bash-hackers.org/howto/conffile
And BashFAQ on eval:
http://mywiki.wooledge.org/BashFAQ/048
What you could do instead is use an ini parser in a different language, and use while/read to process the output. e.g:
https://github.com/andrewgregory/pacuti … c/pacini.c
while read -r foo _ bar; do
printf -v "$foo" '%q' "$bar"
done < <(pacini baz.conf)
%q additionally adds shell escapes.
This little discourse aside, why do you need a config file? You could simply use command-line options and defaults declared at the top of the script.
Last edited by Alad (2016-07-04 15:19:51)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
This little discourse aside, why do you need a config file? You could simply use command-line options and defaults declared at the top of the script.
Thanks for the tip, Alad. See this commit for a project I created.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline