comamnds running interactively, failed in script wrigint
Hi all,
I am trying to run these commands in shell script, but there seem to be some mistake. Somehow it is not accepting the last important comamnd "eval `scram runtime -sh`". However, when I try them interactively, it works all fine.
SCRIPT
====
any piece of hint is appreciable.
hi corona,
I did not understand. I have tested that piece of code. It just cd in the current working directory.
You've tested it in your home dir, by running it in a manner where $0 can be depended on.
Except, you can't depend on $0. When something that's not you runs it, especially automatic things like cron and so forth, you have no idea what your current dir, and the contents of $0, are going to be. It might start in / with a useless $0 like -bash or something. Or it might give an absolute path you weren't expecting. etc. I keep telling people not to do this but until it breaks down like this, they never understand why.
Try typing echo $0 into your shell for example. I get -bash. That's not any sort of directory.
You've tested it in your home dir, by running it in a manner where $0 can be depended on.
Except, you can't depend on $0. When something that's not you runs it, especially automatic things like cron and so forth, you have no idea what your current dir, and the contents of $0, are going to be. It might start in / with a useless $0 like -bash or something. Or it might give an absolute path you weren't expecting. etc. I keep telling people not to do this but until it breaks down like this, they never understand why.
Try typing echo $0 into your shell for example. I get -bash. That's not any sort of directory.
I just tested that piece of code as script like this [1] and the output is [2] just as I want it to be.
It take me back to my working directory.
$0 does not mean "path to my program". That's what it traditionally is, and it's what you get whenever a shell runs a program, but when something that's not a shell runs your program, that's not guaranteed by any means. cron will give weird values for $0. CGI gives weird values for $0. And so forth.
So yes... It does when you run it, from a terminal, giving it an absolute path. When things other than you run it, from non-terminals, in ways and from places you never did, you might get something else.
These two C programs show how it works:
So, when you run ./printzero by itself, the shell runs it, and $0 is what you expect.
When the zero program runs printzero, it can give whatever weird and wild value it wants to $0, and does.
Some shells will make a halfhearted attempt to correct the value of $0 into something 'useful', but they're not psychic. They can't recover paths they were never given in the first place.
So $0 is only what the program calling it says it is. It's not necessarily the information you want. Do not depend on it if you want your scripts to be run by cron and the like.
Last edited by Corona688; 09-25-2012 at 06:14 PM..
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)