nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Config Parameter Expansion - How does it works?

This is a discussion on Config Parameter Expansion - How does it works? within the Shell scripting forums, part of the Development/Scripting category; if I add postfix_enable:="YES" in /etc/rc.conf postfix service starts on boot. However, if I don't it will not start on ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2009, 01:53 PM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 276
Thanks: 32
Thanked 7 Times in 7 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default Config Parameter Expansion - How does it works?

if I add postfix_enable:="YES" in /etc/rc.conf postfix service starts on boot. However, if I don't it will not start on boot. This is easy to understand, but /usr/local/etc/rc.d/postfix startup script has small parameter expansion
Code:
: ${postfix_enable:="NO"}
How does it works? How this small code tells script whether postfix_enable set to YES or not in /etc/rc.conf file? Why : used before ${postfix_enable:="NO"}? Here is sample script:
Code:
. /etc/rc.subr

name="postfix"
rcvar=${name}_enable

load_rc_config $name

: ${postfix_enable:="NO"}
: ${postfix_pidfile:="/var/spool/postfix/pid/master.pid"}
: ${postfix_procname:="/usr/local/libexec/postfix/master"}
: ${postfix_flags:=""}

start_cmd=${name}_start
stop_cmd=${name}_stop
extra_commands="reload"

pidfile=${postfix_pidfile}
procname=${postfix_procname}

postfix_start() {
        /usr/local/sbin/postfix ${postfix_flags} start
}

postfix_stop() {
        /usr/local/sbin/postfix ${postfix_flags} stop
}

run_rc_command "$1"
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #2 (permalink)  
Old 07-05-2009, 08:38 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Posts: 2,450
Thanks: 11
Thanked 189 Times in 139 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

If postfix_enable is defined AND NOT EMPTY, use postfix_enable value; otherwise, use "NO". Try it the following at terminal:
Code:
vech="BUS"
echo $vech
echo ${vech:="CAR"}
vech=""
echo ${vech:="CAR"}
if vech is not defined set its default value to CAR. line # 4 makes vech empty, thus default value set to car. This is known as parameter expansion. See bash man page for other fancy usage.
Code:
man bash
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
raj (07-08-2009)
  #3 (permalink)  
Old 07-08-2009, 11:52 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 276
Thanks: 32
Thanked 7 Times in 7 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

Thanks!

Um..I'm not able to edit my post and add [Solved] prefix.
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #4 (permalink)  
Old 07-08-2009, 12:11 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Posts: 2,450
Thanks: 11
Thanked 189 Times in 139 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by raj View Post
Um..I'm not able to edit my post and add [Solved] prefix.
Must be permission issue. I will look into it ASAP.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply

Tags
bash parameter expansion , ksh parameter expansion , parameter expansion , shell parameter expansion


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
how autosys works with crontab in unix minalsilimkar Solaris/OpenSolaris 0 01-19-2009 08:31 PM
How Linux modprobe command works and find out path for modules? shariefbe Linux software 2 12-21-2008 12:43 AM
How to pass a parameter to a shell script flyingrat Shell scripting 3 07-24-2008 03:01 PM
Increasing the KERNEL parameter sathiya Ubuntu / Debian 4 02-01-2008 11:36 AM
iptables config 6881 Linux software 1 01-28-2006 12:23 PM


All times are GMT +5.5. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38