Solved

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

Posted on 2014-12-02
2
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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