04-07-2013
Here are some
reasons why is
$(...) preferred over
`...` (backticks)?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I'm using the following command to zip a project file, but when it finishes, the resulting zip file contains all the directories above the file I wanted zipped, myapp.app, each one empty until you get to the actual app.
zip -r myapp.app.zip ... (0 Replies)
Discussion started by: groundlevel
0 Replies
2. Shell Programming and Scripting
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... (3 Replies)
Discussion started by: jeriryan87
3 Replies
3. Shell Programming and Scripting
I have a pel script running as root that needs to read the contents of a file on a remote system, I have an ssh trust relationship as a particular user but not as root.
I then need to write back out to that file again to change it's content a bit.
On the surface this seemed really easy but... (3 Replies)
Discussion started by: Smiling Dragon
3 Replies
4. 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
5. Google Chrome OS
sdfdefgsrg (2 Replies)
Discussion started by: frankycool
2 Replies
6. Shell Programming and Scripting
Well, I think I've managed to take two different issues and conglomerate them into and embarrasing mess.
#!/bin/bash
# Set some variables
dir1=/path/that/isnt/variable/$variabledir/dir/
dir2=/path/that/isnt/variable/$variabledir/important/"$variabledir"-subdirectory/path/
echo "Gimme... (7 Replies)
Discussion started by: karlp
7 Replies
7. 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
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 have the basic command written in bash
for element in 1 2
do
if ]; then
set el = "t"
else
set el = "p"
fi
done
but i get the following error
syntax error near unexpected token `for'
` for element in 1 2'
What should i do differently? (3 Replies)
Discussion started by: ncwxpanther
3 Replies
10. Shell Programming and Scripting
The variables given are already defined ($file1-$file3, $obsid1-$obsid3, and $n=3). When I go to run the code, the terminal outputs "Missing }." I believe the error is with the nesting of variables. It would save a lot of time getting this while loop working.
set i = 1
while (${i} <=... (5 Replies)
Discussion started by: ojdefdidit
5 Replies
LEARN ABOUT DEBIAN
perl::critic::policy::inputoutput::prohibitbacktickoperators
Perl::Critic::Policy::InputOutput::ProhibitBacktickOperaUser(Contributed Perl DocPerl::Critic::Policy::InputOutput::ProhibitBacktickOperators(3pm)
NAME
Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators - Discourage stuff like "@files = `ls $directory`".
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
Backticks are super-convenient, especially for CGI programs, but I find that they make a lot of noise by filling up STDERR with messages
when they fail. I think its better to use IPC::Open3 to trap all the output and let the application decide what to do with it.
use IPC::Open3 'open3';
$SIG{CHLD} = 'IGNORE';
@output = `some_command`; #not ok
my ($writer, $reader, $err);
open3($writer, $reader, $err, 'some_command'); #ok;
@output = <$reader>; #Output here
@errors = <$err>; #Errors here, instead of the console
CONFIGURATION
Alternatively, if you do want to use backticks, you can restrict checks to void contexts by adding the following to your .perlcriticrc
file:
[InputOutput::ProhibitBacktickOperators]
only_in_void_context = 1
The purpose of backticks is to capture the output of an external command. Use of them in a void context is likely a bug. If the output
isn't actually required, "system()" should be used. Otherwise assign the result to a variable.
`some_command`; #not ok
$output = `some_command`; #ok
@output = `some_command`; #ok
NOTES
This policy also prohibits the generalized form of backticks seen as "qx{}".
See perlipc for more discussion on using "wait()" instead of "$SIG{CHLD} = 'IGNORE'".
You might consider using the "capture()" function from the IPC::System::Simple module for a safer way of doing what backticks do,
especially on Windows. The module also has a safe wrapper around "system()".
AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
perl v5.14.2 2012-06-07 Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators(3pm)