Sponsored Content
Full Discussion: two commands on 1 line
Top Forums UNIX for Advanced & Expert Users two commands on 1 line Post 43678 by kduffin on Thursday 20th of November 2003 09:42:13 PM
Old 11-20-2003
Also, if you want to conditionally execute the second command based on the return code of the first you can use || or &&.

<command1> && <command2> will execute command2 if command1 returns a value >= 0 (ie success).

<command1> && <command2> will exeucte command2 if command1 returns a value < 0 (ie failure)

Cheers,

Keith
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Commands and Command Line Flags

Hello I'm very new to unix, am learning it as part of my new job. I have a book which has a list in the back, of a number of commands and their command line flags, detailing what these flags are used for. I've been looking everywhere for an electronic copy of this type of list, so I can... (4 Replies)
Discussion started by: Kedgeboy
4 Replies

2. Shell Programming and Scripting

Seperate commands on the same line

hello, is there a way to seperate commands that are on the same line? ie: echo "yes count(*)>0:" $passvar > dsp cat dsp cat dsp > log i'm trying to put these 3 commands on the same line, but when i do they all get concatenated into 1 lieteral if i put the cat commands on... (3 Replies)
Discussion started by: bobk544
3 Replies

3. UNIX for Dummies Questions & Answers

How to get nth line from a file usuing commands

Hi to all, I have a file with 1000 lines,Now i need to get 789th record.So please any one help me out from this. Thanks in advance. Sathish (3 Replies)
Discussion started by: bsathishmca
3 Replies

4. Shell Programming and Scripting

Unix commands in one line

Hi I want to write the following code in 1 line: a=1 if then echo ok else echo not ok fi The following does not work: a=1 ; if \r then \r echo ok \r else \r echo not ok \r fi or Even if I replace \r by \n it does not work. Please suggest. (11 Replies)
Discussion started by: miltonkeynesguy
11 Replies

5. UNIX for Dummies Questions & Answers

Running two commands in one line

hi! how do i run 2 command from the same line e.g: 'which screen' and then ls -la 'which screen' (4 Replies)
Discussion started by: rdns
4 Replies

6. Shell Programming and Scripting

Putting multiple sed commands on a single line

Hi, I want to make sed write a part of fileA (first 7 lines) to file1 and the rest of fileA to file2 in a single call and single line in sed. If I do the following: sed '1,7w file1; 8,$w file2' fileA I get only one file named file1 plus all the characters following file1. If I try to use curly... (1 Reply)
Discussion started by: varelg
1 Replies

7. UNIX for Dummies Questions & Answers

How do you use UNIX commands in the Windows Command Line?

I tried opening the windows command line and typing UNIX commands, but they don't work. It kept saying that it was not recognized as an internal or external command, operable program or batch file. Removed strange sentence with even stranger link I need to use UNIX commands such as 'less',... (9 Replies)
Discussion started by: vlay2
9 Replies

8. UNIX for Dummies Questions & Answers

Multiple Commands on a Single Line

Hi There, I have a cronjob that executes a small script (few lines) that I am certain can be achieved in a single line. The functional objective is actually really simple; cmd var1 The '1' in 'var1' is actually derived from date (day of month) but the snag is when working with 1-9 I... (3 Replies)
Discussion started by: Random79
3 Replies

9. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

10. Shell Programming and Scripting

Csh - how to combine multiple commands in one line

Hey everyone, I am working in an environment where the different users can use ksh or csh. My situation is that I need the same result with one single command line. I am searching for the real path the file is in. My ksh input and output ts2:ts2adm> cd $(dirname $(which sapcontrol)); pwd -P... (2 Replies)
Discussion started by: h1kelds
2 Replies
regex(1F)                                                          FMLI Commands                                                         regex(1F)

NAME
regex - match patterns against a string SYNOPSIS
regex [-e] [ -v "string"] [ pattern template] ... pattern [template] DESCRIPTION
The regex command takes a string from the standard input, and a list of pattern / template pairs, and runs regex() to compare the string against each pattern until there is a match. When a match occurs, regex writes the corresponding template to the standard output and returns TRUE. The last (or only) pattern does not need a template. If that is the pattern that matches the string, the function simply returns TRUE. If no match is found, regex returns FALSE. The argument pattern is a regular expression of the form described in regex(). In most cases, pattern should be enclosed in single quotes to turn off special meanings of characters. Note that only the final pattern in the list may lack a template. The argument template may contain the strings $m0 through $m9, which will be expanded to the part of pattern enclosed in ( ... )$0 through ( ... )$9 constructs (see examples below). Note that if you use this feature, you must be sure to enclose template in single quotes so that FMLI does not expand $m0 through $m9 at parse time. This feature gives regex much of the power of cut(1), paste(1), and grep(1), and some of the capabilities of sed(1). If there is no template, the default is $m0$m1$m2$m3$m4$m5$m6$m7$m8$m9. OPTIONS
The following options are supported: -e Evaluates the corresponding template and writes the result to the standard output. -v "string" Uses string instead of the standard input to match against patterns. EXAMPLES
Example 1: Cutting letters out of a string To cut the 4th through 8th letters out of a string (this example will output strin and return TRUE): `regex -v "my string is nice" '^.{3}(.{5})$0' '$m0'` Example 2: Validating input in a form In a form, to validate input to field 5 as an integer: valid=`regex -v "$F5" '^[0-9]+$'` Example 3: Translating an environment variable in a form In a form, to translate an environment variable which contains one of the numbers 1, 2, 3, 4, 5 to the letters a, b, c, d, e: value=`regex -v "$VAR1" 1 a 2 b 3 c 4 d 5 e '.*' 'Error'` Note the use of the pattern '.*' to mean "anything else". Example 4: Using backquoted expressions In the example below, all three lines constitute a single backquoted expression. This expression, by itself, could be put in a menu defini- tion file. Since backquoted expressions are expanded as they are parsed, and output from a backquoted expression (the cat command, in this example) becomes part of the definition file being parsed, this expression would read /etc/passwd and make a dynamic menu of all the login ids on the system. `cat /etc/passwd | regex '^([^:]*)$0.*$' ' name=$m0 action=`message "$m0 is a user"`'` DIAGNOSTICS
If none of the patterns match, regex returns FALSE, otherwise TRUE. NOTES
Patterns and templates must often be enclosed in single quotes to turn off the special meanings of characters. Especially if you use the $m0 through $m9 variables in the template, since FMLI will expand the variables (usually to "") before regex even sees them. Single characters in character classes (inside []) must be listed before character ranges, otherwise they will not be recognized. For exam- ple, [a-zA-Z_/] will not find underscores (_) or slashes (/), but [_/a-zA-Z] will. The regular expressions accepted by regcmp differ slightly from other utilities (that is, sed, grep, awk, ed, and so forth). regex with the -e option forces subsequent commands to be ignored. In other words, if a backquoted statement appears as follows: `regex -e ...; command1; command2` command1 and command2 would never be executed. However, dividing the expression into two: `regex -e ...``command1; command2` would yield the desired result. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
awk(1), cut(1), grep(1), paste(1), sed(1), regcmp(3C), attributes(5) SunOS 5.10 12 Jul 1999 regex(1F)
All times are GMT -4. The time now is 10:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy