I am new to bash. I am trying to get a sub string of a variable in a shell script. While trying to do that I get the following error:
------------------------------------------------------------------------
OHOME: /aaa/bbb/product/eee ./t.sh: line 6: /aaa/bbb/product/eee: No such file or directory
Oracle Base:
------------------------------------------------------------------------
I am very surprised. Since it does not seem to like "echo $OHOME" I tried several things like enclosing in brackets, single/double quotes, etc. I still get this error. I cannot seem to find the syntax from the book or google
Looks very simple, but I am stuck on this for hours. Maybe experts here can guide me.
Here is our Linux version:
Linux <name> 2.6.9-67.0.20.ELsmp #1 SMP Wed Jun 18 12:40:47 EDT 2008 i686 i686 i386 GNU/Linux
Your command means OHOME=echo and while that assignment is in place, run the command $OHOME which of course is not a valid command.
To capture the output of a command, put it in backticks (ASCII 96, not regular straight quotes):
$OHOME should properly be in double quotes, learn that now and you will get fewer surprises later (although in this case it doesn't really make a difference).
If your shell allows $(...) instead of backticks `...` that is perhaps more readable, although nominally less portable to legacy Bourne shell.
Your awk script doesn't appear to do anything with the a part, if you mean to capture it, you need to print it.
To strip off everything after the first occurrence of /product/ you can use the shell's variable substitution mechanism:
(Your awk script skips the first component /aaa, is that intentional? You can remove that with another variable substitution, O_BASE=${O_BASE#/aaa})
Last edited by era; 08-28-2008 at 03:56 PM..
Reason: Variable substitution remarks
Ahhh.. Thanks a lot. I forgot the `s when I copied it over from HP. It works with both `` and $(..)
Your second suggestion "O_BASE=${OHOME%/product/*}" works perfectly without all the extras. I cannot understand that one - need to get a good book to learn that syntax.
On the third part, the way this awk works is, it assumes the part before the first slash as a field: "/aaa/bbb/product/eee". In this one, aaa is the second field per awk and bbb is the third field.
I forgot the `s when I copied it over from HP. It works with both `` and $(..)
Yes, because HP-UX's sh is a Posix shell. See man sh-posix to find out about its capabilities.
Therefore, you should rather use the $(...) style if you don't intend to run the script
unmodified on AIX's or SunOS/Solaris' sh.
this Reference Cards apendix from the Advanced Bash Scripting Guide (http://tldp.org/LDP/abs/html/) has been a boon to me 'cos I can never remember the correct syntax for string slicing.
In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ?
--- Post updated at 08:39 AM ---
in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
So I'm trying to pass certain json elements as env vars and use them later on in a script.
Sample json:
JSON='{
"Element1": "file-123456",
"Element2": "Name, of, company written in, a very weird way",
"Element3": "path/to/some/file.txt",
}'
(part of the) script:
for s... (5 Replies)
So I am pretty new to the linux environment, and I am trying to create a shell that uses multiple pipes, and I read online that piping using shared memory space is more efficient than using regular piping. However, I have zero clue how to use shared memory space with pipes. Has anyone done this... (1 Reply)
Hello,
I was trying to split a string to characters by perl oneliner.
echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe:
echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8
1 T
1... (6 Replies)
Hi ,
I have following code in my shell script :
"$TS_BIN/tranfrmr" "${TS_SETTINGS}/tranfrmr_p1.stx" "${TS_LOGS}/tranfrmr_p1.err" | (
"$TS_BIN/cusparse" "${TS_SETTINGS}/cusparse_p2.stx" "${TS_LOGS}/cusparse_p2.err" | (
"$TS_BIN/tsqsort" "${TS_SETTINGS}/srtforpm_p3.stx"... (8 Replies)
Hi all. I am using procmail to deliver an email to a script I am developing. Procmail delivers the email to the script on standard input. I imagine this is the same as piping input from a command into the script. Hence I've been testing my script by running
echo 'test' | sms-autosend-backup.sh
... (2 Replies)
I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done.
I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Is it possible to pipe a command in to an instant messenger e.g pidgin, finch or something similar and have it send??? e.g echo "hello" | messenger Or is there anything similar?? Thanks in advance! (1 Reply)