07-02-2007
Backticks within backticks?
Hi, I'm trying to do something like this: range= `expr `date '+%m'` - 1` and it does not work. How can I tell it to evaluate an expression within another expression evaluation? I was at first worried that `date '+%m'` would return a string but apparently expr does the math okay normally, so the problem is how to get it to evaluate an inner set of backticks within the outer set of backticks. Thanks.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Can someone explain the difference between backticks and system when
evaluated in these if statements:
sub getDate {
print "start date\n";
if ( system("/bin/date") ) {
print "can't get date\n";
exit(2);
}
print "finish date\n";
}
Returns the following:
start date
Thu... (5 Replies)
Discussion started by: gjkeenan
5 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I would like to change some lines in my mysql-dump, because there a syntax problems with some version of mysql.
I 'd like to change
USE ´someDatabase´;
to
USE someDatabase;
(without backticks) using the sed command in the shell
Thanks & best regards
Bernd (5 Replies)
Discussion started by: bjb
5 Replies
3. Shell Programming and Scripting
I'm always concerned I might be abusing backticks within my scripts. A current script I'm writing has this for example:
stripscriptname=`echo $scriptname | sed 's/\(.*\)\..*/\1/'`
stripsearch=`echo $searchpattern | tr -d ' ,/'`
Both of these variables are set inside the script (in fact,... (2 Replies)
Discussion started by: mglenney
2 Replies
4. Shell Programming and Scripting
Hey all. Just a fast question, what is the technical difference between using back ticks and using xargs to perform a command?
Here's an example
Find /mydir -name *.conf |xargs rm
Vs
Rm 'find /mydir -name *.conf'
Is there a performance hit? I know they do the same thing but which is... (1 Reply)
Discussion started by: msarro
1 Replies
5. Red Hat
Hi everyone. This is a bit of a perl/linux mixed question. I am trying to redirect STDOUT of chsh by using the following line of perl code.
system ("chsh -s /sbin/nologin $testing 1>/dev/null");
This should redirect STDOUT to /dev/null but it won't do that for some odd reason. Any ideas or... (6 Replies)
Discussion started by: austinharris43
6 Replies
6. Shell Programming and Scripting
Input file:
'data_1'
'data_10'
'data1311'
'235data_13'
Desired output:
data_1
data_10
data1311
235data_13
Can I know how to remove back tick"'" in a file?
Many thanks for advice. (3 Replies)
Discussion started by: perl_beginner
3 Replies
7. Shell Programming and Scripting
Hi all,
Here is my code:
my $x = `bash -c \" ls -l filename | awk '{print \$5}'\"`;
print "$x\n";
This will run the first part of the bash script but not the awk command. It therefore gives output of:
-rw-r--r-- 1 root root 13619200 2012-04-25 08:16 filename
I am actually trying to... (0 Replies)
Discussion started by: free2rhyme2k
0 Replies
8. Shell Programming and Scripting
I have been testing a new script and cannot figure out why my `cat spath` will not execute on the remote machine?
sudo ssh -p 22344 -o "PasswordAuthentication no" -o "HostbasedAuthentication yes" -l testuser 192.168.1.6 "find `cat spath` -depth"
cat: spath: No such file or directory
but... (0 Replies)
Discussion started by: metallica1973
0 Replies
9. Shell Programming and Scripting
I'm trying to make a dialog window that prints the output of grep that takes the output of find. Unfortunately my nested backticks don't work.
Here is the dialog window:
dialog --stdout --title "test" --backtitle "test" --msgbox "Test:\n `grep -l "${tablica}" `find $string``" 16 60I think I... (2 Replies)
Discussion started by: Starting_Leaf
2 Replies
10. UNIX for Advanced & Expert Users
But I love my back-ticks - I know exactly how to escape them (after too many years) - I always seem to end unbalanced with ().
However, I shall take the hint. (One more trick for this dog... aka - not too old yet!) :);) (17 Replies)
Discussion started by: MichaelFelt
17 Replies
EXPR(1) General Commands Manual EXPR(1)
NAME
expr - evaluate arguments as an expression
SYNOPSIS
expr arg ...
DESCRIPTION
The arguments are taken as an expression. After evaluation, the result is written on the standard output. Each token of the expression is
a separate argument.
The operators and keywords are listed below. The list is in order of increasing precedence, with equal precedence operators grouped.
expr | expr
yields the first expr if it is neither null nor `0', otherwise yields the second expr.
expr & expr
yields the first expr if neither expr is null or `0', otherwise yields `0'.
expr relop expr
where relop is one of < <= = != >= >, yields `1' if the indicated comparison is true, `0' if false. The comparison is numeric if
both expr are integers, otherwise lexicographic.
expr + expr
expr - expr
addition or subtraction of the arguments.
expr * expr
expr / expr
expr % expr
multiplication, division, or remainder of the arguments.
expr : expr
The matching operator compares the string first argument with the regular expression second argument; regular expression syntax is
the same as that of ed(1). The (...) pattern symbols can be used to select a portion of the first argument. Otherwise, the
matching operator yields the number of characters matched (`0' on failure).
( expr )
parentheses for grouping.
Examples:
To add 1 to the Shell variable a:
a=`expr $a + 1`
To find the filename part (least significant part) of the pathname stored in variable a, which may or may not contain `/':
expr $a : '.*/(.*)' '|' $a
Note the quoted Shell metacharacters.
SEE ALSO
sh(1), test(1)
DIAGNOSTICS
Expr returns the following exit codes:
0 if the expression is neither null nor `0',
1 if the expression is null or `0',
2 for invalid expressions.
7th Edition April 29, 1985 EXPR(1)