Solved

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

Posted on 2014-12-02
2
170 Views
Last Modified: 2014-12-02
hello

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/SD.py; break;;
        [720]* )  python ./files/HD.py; break;;
        [1080]* ) python ./files/FHD.py; break;;
        * ) echo "répondé a cette question pour continuer";;
    esac
done

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

tx
0
Comment
Question by:hexo dark
2 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 40475483
There are many ways to do this, but one option would be to have a file called ~/res.cfg containing, for example
RES=480

Open in new window

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

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.
0
 
LVL 2

Author Closing Comment

by:hexo dark
ID: 40475551
nikel it works !!!!!! ty
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question