Archive for May, 2007

$ find . ( -name _* -or -newer (Web hosting)

Tuesday, May 8th, 2007

$ find . ( -name _* -or -newer while2 ) -type f -print./elif3./words.txt./words2.txt./_break./_if./_set./_shift./_trap./_unset./_until$ See, that wasn t so hard, was it? We had to escape the parentheses so that they were not processed and also quote the *so that it was passed directly into findas well. Now that we can reliably search for files, let s look at the actions we can perform when we find a filematching our specification. Again, this is just a list of the most common actions; the manual page has set. ActionMeaning-exec commandExecute a command. This is one of the most common actions See theexplanation following this table for how parameters may be passed command. -ok commandLike -exec, except that it prompts for user confirmation of each file it will carry out the command before executing the command. -printPrints out the name of the file. -lsUses the command ls -dilson the current file. The -execand -okcommands take subsequent parameters on the line as part of their parameters, with a ;sequence. The magic string {}is a special type of parameter to an -execor -and is replaced with the full path to the current file. That explanation is perhaps not so easy to understand, but an example should make things clearer. Let s see a simpler example, using a nice safe command like ls: $ find . -newer while2 -type f -exec ls -l {} ; -rwxr-xr-x 1 rick rick 275 Feb 8 17:07 ./elif3-rwxr-xr-x 1 rick rick 336 Feb 8 16:52 ./words.txt-rwxr-xr-x 1 rick rick 1274 Feb 8 16:52 ./words2.txt-rwxr-xr-x 1 rick rick 504 Feb 8 18:43 ./_trap$ As you can see, the findcommand is extremely useful; it just takes a little practice to use it well. However, that practice will pay dividends, so do experiment with the findcommand.
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision shared web hosting services

We can also combine tests using operators. Most (Web hosting e commerce)

Tuesday, May 8th, 2007

We can also combine tests using operators. Most have two forms: a short form and a longer form: Operator, Short FormOperator, Long FormMeaning!-notInvert the test. -a-andBoth tests must be true. -o-orEither test must be true. We can force the precedence of tests and operators by using parentheses. Since these have a specialmeaning to the shell, we also have to quote the braces using a backslash. In addition, if we use a patternfor the filename, we must use quotes so that the name is not expanded by the shell but passed directly tothe findcommand. So if we wanted to write the test newer than file X or called a name that starts withan underscore we would write the following test: (-newer X -o -name _* ) We will present an example just after the next How it Works section. Try It Out find with TestsLet s try searching in the current directory for files modified more recently than the file while2: $ find . -newer while2 -print. ./elif3./words.txt./words2.txt./_trap$ That looks good, except that we also find the current directory, which we didn t want; we were inter- ested only in regular files. So we add an additional test, -type f: $ find . -newer while2 -type f -print./elif3./words.txt./words2.txt./_trap$ How It WorksHow did it work? We specified that findshould search in the current directory (.), for files newer thanthe file while2(-newer while2) and that, if that test passed, then to also test that the file was a regularfile (-type f). Finally, we used the action we already met, -print, just to confirm which files we hadfound. Now let s also find files that either start with an underscore or are newer than the file while2, but mustin either case be regular files. This will show us how to combine tests using parentheses: 64Chapter
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

This is where the first of (Adult web hosting) the options

Monday, May 7th, 2007

This is where the first of the options comes in. If we specify -mount, we can tell findnot to searchmounted directories: # find / -mount -name wish -print/usr/bin/wish# We still find the file, but without searching other mounted file systems. The full syntax for the findcommand is: find [path] [options] [tests] [actions] The pathpart is nice and easy: We can use either an absolute path, such as /bin, or a relative path, .. If we need to, we can also specify multiple paths, for example find /var /home. There are several options; the main ones are as follows: OptionMeaning-depthSearch the contents of a directory before looking at the directory itself. -followFollow symbolic links. -maxdepths NSearch at most Nlevels of directory when searching. -mount(or -xdev)Don t search directories on other file systems. Now for the tests. There are a large number of tests that can be given to find, and each test returnseither trueor false. When findis working, it considers each file it finds in turn and applies each in the order they were defined, on that file. If a test returns false, findstops considering the file it looking at and moves on; if the test returns true, findwill process the next test or action current file. The tests we list in the following table are just the most common; consult the manualpages for the extensive list of possible tests you can apply using find. TestMeaning-atime NThe file was last accessed Ndays ago. -mtime NThe file was last modified Ndays ago. -name patternThe name of the file, excluding any path, matches the pattern pro- vided. To ensure that the pattern is passed to find, and not evalu- ated by the shell immediately, the pattern must always be in quotes. -newer otherfileThe file is newer than the file otherfile. -type CThe file is of type C, where Ccan be of a particular type; the mostcommon are d for a directory and f for a regular file. For othertypes consult the manual pages. -user usernameThe file is owned by the user with the given name.
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision ftp web hosting services

Web host forum - unsetThe unsetcommand removes variables or functions from the

Monday, May 7th, 2007

unsetThe unsetcommand removes variables or functions from the environment. It can t do this to read-onlyvariables defined by the shell itself, such as IFS. It s not often used. The following script writes Hello Worldonce and a newline the second time: #!/bin/shfoo= Hello World echo $foounset fooecho $fooTwo More Useful Commands and Regular ExpressionsBefore we see how we can put this new knowledge of shell programming to use, let s look at a couple ofother very useful commands, which, although not part of the shell, are often useful when writing shellprograms. Along the way we will also be looking at regular expressions, a pattern-matching feature thatcrops up all over Linux and its associated programs. The find CommandThe first command we will look at is find. This command, which we use to search for files, is extremelyuseful, but newcomers to Linux often find it a little tricky to use, not least because it takes options, tests, and action-type arguments, and the results of one argument can affect the processing of subsequentarguments. Before we delve into the options, tests, and arguments, let s look at a very simple example for the filewishon our local machine. We do this as root to ensure that we have permissions to search the wholemachine: # find / -name wish -print/usr/bin/wish# As you can probably guess, this says search starting at / for a file named wishand then print out thename of the file. Easy, wasn t it? However, it did take quite a while to run, and the disk on a Windows machine on the network rattledaway as well. The Linux machine mounts (using SAMBA) a chunk of the Windows machine s file sys- tem. It seems like that might have been searched as well, even though we knew the file we were lookingfor would be on the Linux machine. Writing foo=would have a very similar effect, but not identical, to unsetin thepreceding program. Writing foo=has the effect of setting footo null, but foostillexists. Using unset foohas the effect of removing the variable foofrom theenvironment. 62Chapter
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision personal web hosting services

Php web hosting - echo press interrupt (CTRL-C) to interrupt …. while

Monday, May 7th, 2007

echo press interrupt (CTRL-C) to interrupt …. while [ -f /tmp/my_tmp_file_$$ ]; doecho File existssleep 1doneecho The file no longer existstrap INTecho creating file /tmp/my_tmp_file_$$ date > /tmp/my_tmp_file_$$ echo press interrupt (control-C) to interrupt …. while [ -f /tmp/my_tmp_file_$$ ]; doecho File existssleep 1doneecho we never get hereexit 0If we run this script, pressing Ctrl+C (or whatever your interrupt keys are) in each of the loops, we following output: creating file /tmp/my_tmp_file_141press interrupt (CTRL-C) to interrupt …. File existsFile existsFile existsFile existsThe file no longer existscreating file /tmp/my_tmp_file_141press interrupt (CTRL-C) to interrupt …. File existsFile existsFile existsFile existsHow It WorksThis script uses the trapcommand to arrange for the command rm -f /tmp/my_tmp_file_$$to when an INT(interrupt) signal occurs. The script then enters a whileloop that continues file exists. When the user presses Ctrl+C, the statement rm -f /tmp/my_tmp_file_$$is executed, and then the whileloop resumes. Since the file has now been deleted, the first whileloop terminatesnormally. The script then uses the trapcommand again, this time to specify that no command be executed whenan INTsignal occurs. It then recreates the file and loops inside the second whilestatement. When presses Ctrl+C this time, there is no statement configured to execute, so the default behavior occurs, which is to immediately terminate the script. Since the script terminates immediately, the final echoandexitstatements are never executed.
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Yahoo web hosting - trapThe trapcommand is used for specifying the actions

Monday, May 7th, 2007

trapThe trapcommand is used for specifying the actions to take on receipt of signals, which we ll meet inmore detail later in the book. Acommon use is to tidy up a script when it is interrupted. Historically, shells always used numbers for the signals, but new scripts should use names taken from the #includefile signal.h, with the SIGprefix omitted. To see the signal numbers and associated names, you canjust type trap -lat a command prompt. The trapcommand is passed the action to take, followed by the signal name (or names) to trap on. trapcommand signalRemember that the scripts are normally interpreted from top to bottom, so you must specify the trapcommand before the part of the script you wish to protect. To reset a trap condition to the default, simply specify the command as -. To ignore a signal, set the com- mand to the empty string . Atrapcommand with no parameters prints out the current list of trapsand actions. The following table lists the more important signals covered by the X/Open standard that can be caught(with the conventional signal number in parentheses). More details can be found under in the signalmanual pages in section 7 of the online manual (man 7 signal). SignalDescriptionHUP(1)Hang up; usually sent when a terminal goes off line, or a user logs outINT (2)Interrupt; usually sent by pressing Ctrl+CQUIT (3)Quit; usually sent by pressing Ctrl+ ABRT (6)Abort; usually sent on some serious execution errorALRM (14)Alarm; usually used for handling timeoutsTERM (15)Terminate; usually sent by the system when it s shutting down Try It Out Trapping SignalsThe following script demonstrates some simple signal handling: #!/bin/shtrap rm -f /tmp/my_tmp_file_$$ INTecho creating file /tmp/my_tmp_file_$$ date > /tmp/my_tmp_file_$$ For those not familiar with signals, they are events sent asynchronously to a program. By default, they normally cause the program to terminate. 60Chapter
Note: If you are looking for best quality webspace to host and run your tomcat application check Vision virtual web hosting services

Suppose we want to use the name of (Tomcat web server)

Sunday, May 6th, 2007

Suppose we want to use the name of the current month in a shell script. The system provides a datecommand, which contains the month as a string, but we need to separate it from the other fields. We this using a combination of the setcommand and the $(…)construct to execute the datecom- mand and return the result (which we ll look at in more detail very soon). The datecommand outputhas the month string as its second parameter: #!/bin/shecho the date is $(date) set $(date) echo The month is $2exit 0This program sets the parameter list to the datecommand s output and then uses the positional param- eter $2to get at the month. Notice that we used the datecommand as a simple example to show how to extract positional parameters. Since the datecommand is sensitive to the language local, in reality we would have extracted the name month using date +%B. The datecommand has many other formatting options; see the manual more details. We can also use the setcommand to control the way the shell executes by passing it parameters. Themost commonly used form of the command is set -x, which makes a script display a trace of executing command. We discuss setand more of its options when we look at debugging, lateron in the chapter. shiftThe shiftcommand moves all the parameter variables down by one, so that $2becomes $1, $3becomes$2, and so on. The previous value of $1is discarded, while $0remains unchanged. If a numerical parame- ter is specified in the call to shift, the parameters will move that many spaces. The other variables $@, and $#are also modified in line with the new arrangement of parameter variables. shiftis often useful for scanning through parameters, and if your script requires 10 or more parameters, you ll need shiftto access the tenth and beyond. Just as an example, we can scan through all the positional parameters like this: #!/bin/shwhile [ $1 != ]; doecho $1 shiftdoneexit 059ShellProgrammingb544977
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Escape SequenceDescriptionbBackspace characterfForm feed characternNewline characterrCarriage returntTab charactervVertical (Zeus web server)

Sunday, May 6th, 2007

Escape SequenceDescriptionbBackspace characterfForm feed characternNewline characterrCarriage returntTab charactervVertical tab characteroooThe single character with octal value oooThe conversion specifier is quite complex, so we ll list only the common usage here. More details can befound in the bash online manual or in the printfpages from section 3 of the online manual (man 3printf). The conversion specifier consists of a %character, followed by a conversion character. The prin- cipal conversions are as follows: Conversion SpecifierDescriptiondOutput a decimal number. cOutput a character. sOutput a string. %Output the %character. The format string is then used to interpret the remaining parameters and output the result. For example, $ printf %sn hellohello$ printf %s %dt%s Hi There 15 peopleHi There 15 peopleNotice how we must use to protect the Hi Therestring and make it a single parameter. returnThe returncommand causes functions to return. We mentioned this when we looked at functions ear- lier. returntakes a single numeric parameter that is available to the script calling the function. If noparameter is specified, returndefaults to the exit code of the last command. setThe setcommand sets the parameter variables for the shell. It can be a useful way of using fields incommands that output space-separated values. 58Chapter
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

The exprcommand is powerful and can perform many (Crystaltech web hosting)

Sunday, May 6th, 2007

The exprcommand is powerful and can perform many expression evaluations. The principal ones following table: Expression EvaluationDescriptionexpr1 | expr2expr1if expr1is nonzero, otherwise expr2expr1 & expr2Zero if either expression is zero, otherwise expr1expr1 = expr2Equalexpr1 > expr2Greater thanexpr1 >= expr2Greater than or equal toexpr1 < expr2Less thanexpr1 <= expr2Less than or equal toexpr1 != expr2Not equalexpr1 + expr2Additionexpr1 - expr2Subtractionexpr1 * expr2Multiplicationexpr1 / expr2Integer divisionexpr1 % expr2Integer moduloIn newer scripts, the use of expris normally replaced with the more efficient $((...))syntax, whichwe discuss later in the chapter. printfThe printfcommand is available only in more recent shells. X/Open suggests that we should use to echofor generating formatted output. The syntax isprintf format string parameter1 parameter2 ... The format string is very similar to that used in C or C++, with some restrictions. Principally, floatingpoint isn t supported, because all arithmetic in the shell is performed as integers. The format string sists of any combination of literal characters, escape sequences, and conversion specifiers. All charactersin the format string other than %and appear literally in the output. The following escape sequences are supported: Escape SequenceDescription\Backslash characteraAlert (ring the bell or beep) Table continued on following
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision best web hosting services

Business web site - Try It Out Exporting Variables1.We list export2first: #!/bin/shecho $foo

Sunday, May 6th, 2007

Try It Out Exporting Variables1.We list export2first: #!/bin/shecho $foo echo $bar 2.Now for export1. At the end of this script, we invoke export2: #!/bin/shfoo= The first meta-syntactic variable export bar= The second meta-syntactic variable export2If we run these, we get$ export1The second meta-syntactic variable$ The first blank line occurs because the variable foowas not available in export2, so $fooevaluated tonothing; echoing a nullvariable gives a newline. Once a variable has been exported from a shell, it s exported to any scripts invoked from that shell andalso to any shell they invoke in turn and so on. If the script export2called another script, it would alsohave the value of baravailable to it. exprThe exprcommand evaluates its arguments as an expression. It s most commonly used for simple arith- metic in the following form: x=`expr $x + 1` The “(back-tick) characters make xtake the result of executing the command expr $x + 1. We couldalso write it using the syntax $( )rather than back ticks, like this: x=$(expr $x + 1) We ll mention more about command substitution later in the chapter. The commands set -aor set -allexportwill export all variables thereafter. 56Chapter
Note: In case you are looking for affordable webhost to host and run your web application check Vision cheap hosting services