LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-21-2004, 05:36 AM   #1
AndiOliver
LQ Newbie
 
Registered: Apr 2004
Location: Romania
Distribution: Red Hat
Posts: 4

Rep: Reputation: 0
Dynamic dialog in bash scripts


This is a small part from a script I am trying to wrote:
Code:
dialog --clear --backtitle "<<<...   PROSOFT COMPUTERS   ...>>> Tel/fax: 40 246 231082" --title "MENIU PRINCIPAL" \
        --menu "Pentru a va deplasa in sus, respectiv in jos - sageti \n\
[Enter] pentru selectare\n\
Alegeti programul dorit:" 30 100 18 \
        "Arhivare"      "Backpup Server Prosoft Computers (Mail, Website, Homesite)" \
        "Alive"         "Verificare serverelor, clientilor online"\
        "Filtru"        "Diverse filtre pentru traficul pe server"\
        "Trafic"        "Estimari trafic reteaua Prosoft Computers"\
        "Programare"    "Programare sectiuni de rulare in mod automat"\
        "Altele"        "Alte comenzi utile in administrare"\
        "Iesire"         "Iesire din program" 2> menuchoice.temp.$$
It is working, but right now I got to the point where the item I would like to load them dynamicaly, from a file.
It seems so far that this dialog won't let me create it unless I put specific items like it is wroted in the example. so my question is:

How can I load dynamicaly items from a file to this dialog?

Thanks in advance for those who help me or tries to...
 
Old 04-21-2004, 09:56 PM   #2
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16
Hi,

I had the same problem a long time ago. My solution was to write a script which creates a script to do this.

The script you have sent is in some language I don't understand. So, I'm just guessing about the contents. My assumption is that you have a file (called dynamicinfo, say) with something like:

Arhivare Backpup Server Prosoft Computers (Mail, Website, Homesite)
Alive Verificare serverelor, clientilor online
Filtru Diverse filtre pentru traficul pe server

So, the script goes something like this: [newfile.sh is the new script that's being created]

Code:
#!/bin/ksh

touch newfile.sh
echo "#!/bin/ksh" >> newfile.sh
echo the first three lines of dialog command too. Use this:

Code:
cat >>newfile.sh <<EOF
dialog --clear --backtitle "<<<...   PROSOFT COMPUTERS   ...>>> Tel/fax: 40 246 231082"\
--title "MENIU PRINCIPAL" \
        --menu "Pentru a va deplasa in sus, respectiv in jos - sageti \n\
[Enter] pentru selectare\n\
EOF
Now, comes the interesting part. You need to read from the file (the file with the dynamic info, dynamicinfo), a whole line and then split it into two parts, one containing the first word and one containing the rest. So, something like this should do:

Code:
while read line
do
    echo "$line" | sed 's/\([^ ]*\) \(.*\)$/"\1" "\2"\\/' >>newfile.sh
done <dynamicinfo

echo '2> menuchoice.temp.$$' >>newfile.sh
Now, the newfile.sh script is ready. Call it with something like:

Code:
ksh newfile.sh
rm -f newfile.sh
I've skipped the parts of checking whether newfile.sh exists, and so on. Be careful!

I'd be glad to help out with anything you did not understand,
Arvind
 
Old 04-22-2004, 01:06 AM   #3
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
in a file named "items" without quotes write the menu info as follows
"Arhivare" "Backpup Server Prosoft Computers (Mail, Website, Homesite)"
"Alive" "Verificare serverelor, clientilor online"
"Filtru" "Diverse filtre pentru traficul pe server"
"Trafic" "Estimari trafic reteaua Prosoft Computers"
"Programare" "Programare sectiuni de rulare in mod automat"
"Altele" "Alte comenzi utile in administrare"
"Iesire" "Iesire din program"

#!/bin/bash
3<>"items";
number=0;
declare -a Items;

while read -u 3
do
echo $REPLY
Items[$number]="$REPLY";
number=`expr $number + 1`;
done

COMMAND='dialog --menu HelloWorld 30 100 18 ';

i=0;
while [ $i -lt $number ]
do
COMMAND="$COMMAND ${Items[$i]}";
i=`expr $i + 1`;
done
COMMAND="$COMMAND 2>tmp.\$\$"
echo $COMMAND > .cmd.$$;
sh .cmd.$$;
 
Old 04-22-2004, 02:46 AM   #4
AndiOliver
LQ Newbie
 
Registered: Apr 2004
Location: Romania
Distribution: Red Hat
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you all for help especially thanks to gizmo_thunder - it worked like charm.
It was just I've wanted to make with my script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dialog command not recognized on debian sarge's bash!!! CM019 Linux - Newbie 2 02-13-2005 03:37 PM
Making shell scripts interactive using dialog saurabh142857 Programming 2 01-03-2005 11:14 AM
bash scripting: dialog --inputbox chibiace Linux - Newbie 1 11-08-2004 10:22 PM
$? in Bash scripts clinton Linux - Newbie 4 02-20-2004 11:15 AM
Bash scripts? BajaNick Programming 3 07-05-2003 10:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration