In shell (Web hosting providers) scripts, the dot command works a
Tuesday, July 31st, 2007In shell scripts, the dot command works a little like the #includedirective in C or C++. Though it doesn tliterally include the script, it does execute the command in the current context, so you can use it to incor- porate variable and function definitions into a script. Try It Out The Dot CommandIn the following example, we use the dot command on the command line, but we can just as well use a script. 1.Suppose we have two files containing the environment settings for two different developmentenvironments. To set the environment for the old, classic commands, classic_set, we bin/shversion=classicPATH=/usr/local/old_bin:/usr/bin:/bin:. PS1= classic> 2.For the new commands we use latest_set: #!/bin/shversion=latestPATH=/usr/local/new_bin:/usr/bin:/bin:. PS1= latest version> We can set the environment by using these scripts in conjunction with the dot command, as in the lowing sample session: $ . ./classic_setclassic> echo $versionclassicclassic> . latest_setlatest version> echo $versionlatestlatest version> echoDespite the X/Open exhortation to use the printfcommand in modern shells, we ve been followingcommon practice by using the echocommand to output a string followed by a newline character. Acommon problem is how to suppress the newline character. Unfortunately, different versions of UNIXhave implemented different solutions. The common method in Linux is to useecho -n string to output but you ll often come acrossecho -e string to outputc