01-30-2017
Quote:
Originally Posted by
Peasant
So if you have small, efficient script with no nested subshells, are backquotes still the lowest denominator e.g will it run without magic cookie on any unix OS ever produced ?
I would never run the risk of having whatever shell executing my code. Out of pure paranoia you won't see any script without a shebang line stating the shell it is intended to run in explicitly.
You see, i once wrote shell scripts for an installed base of ~22k systems worldwide, ranging from IBM 42Ts and 43Ps (desktop systems) up to big SP/2s and everything in between. Believe me, whatever administrative horror you are able to think of - 5 systems somewhere had exactly this and then some.
root not allowed to write a file in
/tmp? Filesystems with no more free inodes? A user named "root" but with a non-0 UID? I have seen all this and more.
Most of my scripts are not "small" therefore. Not, because they do so much, but because they take extreme care of error handling and take nothing i can think of for granted.
Quote:
Originally Posted by
Peasant
Example would be a simple mv script using basename command in subshell.
basename is IMHO a bad example. I would do that with parameter expansion as (in the interest of speed) anything else that could be done with it.
bakunin
9 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. 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. 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
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. 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
6. 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
7. 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
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
LEARN ABOUT OSF1
printenv
env(1) General Commands Manual env(1)
NAME
env, printenv - Displays or sets the current environment, or displays the values of environment variables
SYNOPSIS
Current Syntax
env [-i] [name=value...] [command] [args...]
printenv [name]
Obsolescent Syntax
env [-] [name=value...] [command] [args...]
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
env: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Invokes utility with exactly the environment specified by the arguments; the inherited environment is ignored completely. Changes are in
effect only while the specified command is running. Dash is equivalent to -i option.
OPERANDS
Changes in the form name=value are added to the current environment before the command is run. [Tru64 UNIX] Name of an environment vari-
able to be printed. Name of a command to be invoked with the modified environment. Arguments to be passed to command when it is executed.
DESCRIPTION
The env command lets you get and change your current environment, and then run the specified command with the changed environment. If the
-i option is used, the current environment is ignored and the command runs with only the changed environment. Changes are only in effect
while the specified command is running.
If command is not specified, env displays your current environment, one name=value pair per line.
[Tru64 UNIX] The printenv command displays the values of the variables in the environment. If name is specified, only its value is
printed. If name is not the name of a currently set environment variable, only a blank line is printed, no error is reported. If name is
not specified, printenv displays the current environment, one name=value per line.
EXIT STATUS
If command is invoked, the exit status of env is the exit status of command; otherwise, the env utility exits with one of the following
values: The env utility completed successfully. An error occurred in the env utility. The command specified by command was found but
could not be invoked. The command specified by command could not be found.
EXAMPLES
To add a shell variable to the environment for the duration of one command (sh only), enter: TZ=MST7MDT date env TZ=MST7MDT date
Each of these commands displays the current date and time in Mountain Standard Time. The two commands shown are equivalent. When
date is finished, the previous value of TZ takes effect again. To replace the environment with another one, enter: env -i
PATH=$PATH IDIR=/u/jim/include LIBDIR=/u/jim/lib make
This runs make in an environment that consists only of these definitions for PATH, IDIR, and LIBDIR. You must redefine PATH so that
the shell can find the make command.
When make is finished, the previous environment takes effect again. To find the current setting of the TERM environment variable,
enter: printenv TERM
The command returns the value for the TERM environment variable.
ENVIRONMENT VARIABLES
The following environment variables affect the execution of env: Provides a default value for the internationalization variables that are
unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari-
ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the for-
mat and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of
LC_MESSAGES.
SEE ALSO
Commands: csh(1), ksh(1), Bourne shell sh(1b), POSIX shell sh(1p)
Functions: exec(2)
Standards: standards(5)
env(1)