Bash shell linux : how to create a config files For my script


i create this for the moment on my bash shell
 echo ""
echo "SD (480) HD (720) FHD (1080)"
echo ""
while true; do
    read -p "quelle résolution télécharger" rez
    case $rez in
        [480]* )  python ./files/; break;;
        [720]* )  python ./files/; break;;
        [1080]* ) python ./files/; break;;
        * ) echo "répondé a cette question pour continuer";;

Open in new window

it work  I would rather want to create a file configuration so that my script takes the resolution wanted without intervention

hexo darkAsked:
Who is Participating?
simon3270Connect With a Mentor Commented:
There are many ways to do this, but one option would be to have a file called ~/res.cfg containing, for example

Open in new window

then the code would become
rez=$(awk -F= '$1 ~ /^RES$/{print $2}' ~/res.cfg)
    case $rez in
        480* )  python ./files/;;
        720* )  python ./files/;;
        1080* ) python ./files/;;
        * ) echo "Bad response $rez"; exit 1;;

Open in new window

I've taken out the while loop, because you only want to check the configuration file contents once (so the "break" commands are no longer needed).  I've also exited the script if the configuration item is wrong.

The square brackets in your case statement are wrong - for example, "[480]*" here will match a 4, an 8 or a 0, followed by any characters (so any of 480, 800, 8, 0abc etc).  you just need the bare text.

There are simpler ways to store the configuration information (e.g. just have the actual value, such as "480"), but this method allows for other configuration items to be stored in the same file, if you need them in the future.
hexo darkAuthor Commented:
nikel it works !!!!!! ty
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.