09-25-2012
Quote:
Originally Posted by
nrjrasaxena
just wondering...can I rely this $0 while working with shell script probably?
Only if you know for a fact it's going to be launched from a shell and not by cron or anything.
Quote:
If not, then what could be the other way to write it in shell script.
Either code the path into the script, take it as a parameter, or make it something you can grab by sourcing /etc/profile. That's what it's for, really -- storing global values like that.
Most programs don't keep their data in the same location as the executable, you know, especially if they need to write to it. Writing to the same folder your program exists in could be a recipe for disaster if your program goes wrong -- might delete itself, rename itself, truncate itself, overwrite itself, etc, or be manipulated into doing so by clever/malicious people.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi everybody! I am new to unix; however I already now a few unix commands. I would like a complete document, pdf or anything, to learn them all. Hope you can help me!:confused: (4 Replies)
Discussion started by: cybergang007
4 Replies
2. Shell Programming and Scripting
Hi falks,
I have the following program:
#!/bin/ksh
ed -s /home/ias/v9.0.3/j2ee/OC4J_RiGHTv_HPCD2/applications/Xbip/Xbip/WEB
-INF/config/application.properties <<EOF >/dev/null
1
d
.
d
.
a
application.filePath.core = /core-HPCD2/Html/
application.filePath.xbip =... (2 Replies)
Discussion started by: nir_s
2 Replies
3. Filesystems, Disks and Memory
Hi,
I am running an oracle db 9.2.0.5.0 on ibm p5 550 aix 5.3 with 10g ram, 10G swap space 3 database instances each SGA about 500Meg.
I am getting the following error in my alert log file from time to time:
skgpspawn failed:category = 27142, depinfo = 11, op = fork, loc = skgpspawn3
... (0 Replies)
Discussion started by: hawkerpacific
0 Replies
4. UNIX for Dummies Questions & Answers
Hi. I have a situation where I need to constantly read a command's output in order to loop through it to determine something that is happening over our system. The command td <filename> interactively prints 'filename' as text is written to it and this is redirected to standard output. I have been... (8 Replies)
Discussion started by: fidodido
8 Replies
5. Shell Programming and Scripting
hi,
To search and replace a string in multiple files i am using following command:
find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find_string/replace_string/g'
I want to be prompted while replacing the string.
how this can be done.
thanks for every help. (2 Replies)
Discussion started by: aks__
2 Replies
6. Shell Programming and Scripting
I am trying to fetch failed process but while doing that unable to do so. like;
(1)ps -ef | grep snmpCollect
o/p is coming like -
root 12423 4393 1 19:44:06 pts/0 0:00 grep snmpCollect
(2)ps -ef | grep sttps
o/p-
root 15517 4393 0 19:53:24 pts/0 0:00 grep sttps... (6 Replies)
Discussion started by: kumarabhi84
6 Replies
7. Shell Programming and Scripting
hi,
i have script which installs around 20 packages. during installation of each package script will be prompted for user input.
i need to run the script in non-interactive by using here document. is it possible to generate here document by running the script in interactive mode on Solaris?... (1 Reply)
Discussion started by: snreddy_gopu
1 Replies
8. Solaris
Hi Guys,
I have performed OBP & ALOM upgrade on V240 system. One of my system, running Solaris 10, having issue to identify flash rom during ALOM 1.6.10 version upgrade (OBP upgraded to latest one).
May I know what the reason of this error and how can I fix it so I can upgrade ALOM using... (0 Replies)
Discussion started by: myrpthidesis
0 Replies
9. UNIX for Beginners Questions & Answers
Hi; problem may be obvious, simple but I have to say it is somehow not easy to locate the issue.
I am doing some word extracting from multiline text.
Interacting in CLI seems to work without issues. First step is to add multiline text to a variable.
expect1.1>
expect1.1> set... (2 Replies)
Discussion started by: aldowski
2 Replies
10. UNIX for Beginners Questions & Answers
The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :).
interactively in terminal
dir=/path/to
new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
Discussion started by: cmccabe
6 Replies
SCRIPT(1) User Commands SCRIPT(1)
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file. If no filename is given, the dialogue is saved in the file type-
script.
OPTIONS
-a, --append
Append the output to file or to typescript, retaining the prior contents.
-c, --command command
Run the command rather than an interactive shell. This makes it easy for a script to capture the output of a program that behaves
differently when its stdout is not a tty.
-e, --return
Return the exit code of the child process. Uses the same format as bash termination on signal termination exit code is 128+n.
-f, --flush
Flush output after each write. This is nice for telecooperation: one person does `mkfifo foo; script -f foo', and another can
supervise real-time what is being done using `cat foo'.
--force
Allow the default output destination, i.e. the typescript file, to be a hard or symbolic link. The command will follow a symbolic
link.
-q, --quiet
Be quiet (do not write start and done messages to standard output).
-t[file], --timing[=file]
Output timing data to standard error, or to file when given. This data contains two fields, separated by a space. The first field
indicates how much time elapsed since the previous output. The second field indicates how many characters were output this time.
This information can be used to replay typescripts with realistic typing and output delays.
-V, --version
Display version information and exit.
-h, --help
Display help text and exit.
NOTES
The script ends when the forked shell exits (a control-D for the Bourne shell (sh(1)), and exit, logout or control-d (if ignoreeof is not
set) for the C-shell, csh(1)).
Certain interactive commands, such as vi(1), create garbage in the typescript file. script works best with commands that do not manipulate
the screen, the results are meant to emulate a hardcopy terminal.
It is not recommended to run script in non-interactive shells. The inner shell of script is always interactive, and this could lead to
unexpected results. If you use script in the shell initialization file, you have to avoid entering an infinite loop. You can use for
example the .profile file, which is read by login shells only:
if test -t 0 ; then
script
exit
fi
You should also avoid use of script in command pipes, as script can read more input than you would expect.
ENVIRONMENT
The following environment variable is utilized by script:
SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed.
(Most shells set this variable automatically).
SEE ALSO
csh(1) (for the history mechanism), scriptreplay(1)
HISTORY
The script command appeared in 3.0BSD.
BUGS
script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects.
script is primarily designed for interactive terminal sessions. When stdin is not a terminal (for example: echo foo | script), then the
session can hang, because the interactive shell within the script session misses EOF and script has no clue when to close the session. See
the NOTES section for more information.
AVAILABILITY
The script command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils
/util-linux/>.
util-linux June 2014 SCRIPT(1)