The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Saving changes when using the sed command rc1138 UNIX for Dummies Questions & Answers 3 11-11-2008 11:12 PM
saving a vi session ajcannon Shell Programming and Scripting 0 09-20-2007 05:07 AM
saving macros for VIM yngwie UNIX for Dummies Questions & Answers 3 05-14-2007 01:26 AM
saving from unix into pc alikun UNIX for Dummies Questions & Answers 6 03-28-2007 03:03 AM
Saving to a floppy umether UNIX for Dummies Questions & Answers 1 08-26-2005 06:59 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2009
Moumou Moumou is offline
Registered User
  
 

Join Date: Jul 2009
Location: grenoble
Posts: 32
Saving value as default value

Hi everybody,

I have a prog who is filtering an image with a lot of parameters. The user has two choices :

-Running the script with default values

-Running the script manually (i.e choosing himself the parameters values)

What I would like to do is that if he wants, the users can keep the values he chose as new default values.
WIth stg like a question : "Do you want to keep those values as default? [Y/N]"


And the problem is that I have no idea how to do that....

So if anyone could help me, i'll be very grateful!

Thanks
  #2 (permalink)  
Old 07-20-2009
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by Moumou View Post
What I would like to do is that if he wants, the users can keep the values he chose as new default values.
WIth stg like a question : "Do you want to keep those values as default? [Y/N]"


And the problem is that I have no idea how to do that....
Are you stuck on how to accept the user's option or how to save the default parameters per user ?

To accept the user's option see one of these
making a .sh wait for user input
Getting user input

If you are wondering how to save the parameters, then accept the params for the first time and then dump them onto a file with <key,value> pair like
RUN_ALGO=YES
TRANSFORM=NO et al.
Later, in the next run, look for this file and read the entries.
  #3 (permalink)  
Old 07-20-2009
Moumou Moumou is offline
Registered User
  
 

Join Date: Jul 2009
Location: grenoble
Posts: 32
I was stuck to save values.
Thx for your answers!
  #4 (permalink)  
Old 07-20-2009
kshji's Avatar
kshji kshji is offline
Registered User
  
 

Join Date: Jun 2009
Location: Finland
Posts: 236
Using personal setup file ex. mysetup.txt. This works every posix-sh (ksh, bash, ...).

Code:
#!/bin/ksh
#mysetup
#use:
#mysetup -
#- use mysetup using my own defaut setup
#or
#mysetup
#- ask values and save using previous values as default

set1="sysdefault1"
set2="sysdefault2"
# always use mysetup as default if there is
[ -f $HOME/mysetup.txt ] && . $HOME/mysetup.txt

savedef()
{
   > $HOME/mysetup.txt
   # which variables to save
   for var in set1 set2
   do
        eval echo "\"$var='\$$var'\""  >> $HOME/mysetup.txt
   done
}

askvalues()
{
echo -n "set1 [$set1]:"
read Xset1
[ "$Xset1" != "" ] && set1="$Xset1"
echo -n "set2 [$set2]:"
read Xset2
[ "$Xset2" != "" ] && set2="$Xset2"
savedef
}

#######MAIN####
[ "$1" != "-" ] && askvalues

  #5 (permalink)  
Old 07-20-2009
Moumou Moumou is offline
Registered User
  
 

Join Date: Jul 2009
Location: grenoble
Posts: 32
thx a lot for your answer
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0