Solved

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

Posted on 2014-12-02
2
165 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
Comment Utility
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
Comment Utility
nikel it works !!!!!! ty
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating a Samba server for a small office. Ubuntu Linux and Samba can breathe new life into a retired PC and save an office money on new hardware/software. Our example server will have two hard disks, one exclusively for storing shared data. …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now