Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem Imaging Computers With Clonezilla 2 104
Linux alternative boot CD? 28 149
Whats the correct entry into pg_hba.conf  file 12 109
UBUNTU 12.04 LTS don't finish booting 5 81
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…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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