Solved

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

Posted on 2014-12-02
2
167 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VMWARE Vcenter GUI defaults question about networks 10 86
Can't send mail from centos 7 5 94
Full Backup software for Linux 5 64
Encrypted Laptop running Linux 3 109
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

17 Experts available now in Live!

Get 1:1 Help Now