01-27-2009
To answer the question: "${0}" should be the CURRENT shell name. You could try to get the version information as well (might be limited and I haven't tried that but you should be able to get this from the environment variables).
The calling process is your parent. You should never check your parent's property. If you need - then most probably the application needs an re-design.
My guess is that the parent process should call this code with a pre-formatted text like "{bold}this{red}is{normal}some text". Of course we should ask ourselves whether it is a good idea to use shell scripts here (probably you should use python/perl/some high level language).
To correct your approach: If you call a script then its executable should be specified in the first line (ex. #!/bin/ksh). If you have several scripts and every is written for a different shell - you should execute them and this would execute a new shell/whatever instance. Since every shell seems to be a separate entity (as it seems from your description) - you should either normalize them (re-write everything to the same script/shell/whatever) or just leave them as it is right now without using any common shell script file. There is nothing worse than using thousands of different languages in a single project maintained by thousands of developers.
If your script is called from other scripts (using several different shells to execute them) - then I cannot understand how this is a library script. Maybe this is a script that is executed with some options specified?
By the way: My English is not the the best but bellow you can find somewhat corrected version of your post (maybe someone else can correct it more? or even correct my post?). Sorry for being the fussy kind:
Quote:
Hello,
I have a lib file which contains a function that gets (receive would be better) text to print on to the screen /by/ using echo command.
Several scripts are inculded in this lib and /use/ are using this function.
Each one of them is written in a different shell language (sh ksh & bash).
This is causing some issues when using backslash character as part of the test that /sends to this function/ (Sorry, but I do not understand that part).
I would like to create two echo commands which /will/ would be executed according to the current shell.
How can I extarct the current shell which is used by the calling script /to the print function / to print the text output?
Thanks /a head/ in advance
Alalush
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi -
I m prashant. I m new in UNIX&LINUX world. I want to ask that how can we define the shell in Linux like bash,ksh,csh in Linux. What is the use of these shells. I know there are mny experts on net if you can tell me then please do me this favour and tell me about this topic.
... (1 Reply)
Discussion started by: prashantsingh
1 Replies
2. Shell Programming and Scripting
Hi folks,
I need to stop printing a new line after echoing a string in KSH. i know bash provides
echo -n "string"
what is the ksh equivalent for this ? (3 Replies)
Discussion started by: mudhireddy
3 Replies
3. What is on Your Mind?
Same as the Title!
:) (2 Replies)
Discussion started by: ripat
2 Replies
4. UNIX for Advanced & Expert Users
Hi All,
I'm trying to use the "echo" command in a korn shell script, and I want it to drop the trailing newline. Now I know that with the bash shell, the "-n" flag would solve this issue. Does anyone know how this can be done with the korn shell?
Cheers
Khoom (10 Replies)
Discussion started by: Khoomfire
10 Replies
5. Shell Programming and Scripting
hi
i was trying to optimize one script and i came across this problem .. i am putting some pseudo code here
$ >cat a.sh
ls | while read I
do
i=$(($i + 1))
done
echo "total no of files : "
$ >ksh a.sh
total no of files :
$ >bash a.sh
total no of files :
why is... (1 Reply)
Discussion started by: zedex
1 Replies
6. Shell Programming and Scripting
I am using a Linux machine and it's default shell is BASH . I have korn shell script and inside it's setting environment variables. But after execuitng the script those env values are not holding the values . If I run the script outside of that ksh script with source a.sh , it's able to hold to... (1 Reply)
Discussion started by: talashil
1 Replies
7. Shell Programming and Scripting
I am using a Linux machine and it's default shell is BASH . I have korn shell script and inside it's setting environment variables. But after execuitng the script those env values are not holding the values . If I run the script outside of that ksh script with source a.sh , it's able to hold to... (2 Replies)
Discussion started by: talashil
2 Replies
8. Shell Programming and Scripting
I am learning to build from SVN and other tools, with a lot of copying and pasting from forums. I like to append && echo "success" to all commands so that I can see at a glance if things went all right. Is there a way that I can have the bash shell append this to all commands?
Thanks! (5 Replies)
Discussion started by: dotancohen
5 Replies
9. Shell Programming and Scripting
Dear All,
Please advice about this issue.
when i run this line in a script if && || && || && if i enter $x = test3 and $y = test1 the If condition apply while it should not
Best Regards (2 Replies)
Discussion started by: islam.said
2 Replies
10. Shell Programming and Scripting
#!/usr/bin/ksh
var1="Hi World"
var2="Morning"
var3=$(echo "$var1" \n "$var2")
echo $var3
var3=$(printf "$var1 \n $var2")
echo $var3
Output
Any way to get
in my $var3 ? (7 Replies)
Discussion started by: dahlia84
7 Replies
LEARN ABOUT OSX
set_color
set_color(1) fish set_color(1)
NAME
set_color - set_color - set the terminal color
set_color - set the terminal color
Synopsis
set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR]
Description
Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple,
cyan, white and normal.
o -b, --background Set the background color
o -c, --print-colors Prints a list of all valid color names
o -h, --help Display help message and exit
o -o, --bold Set bold or extra bright mode
o -u, --underline Set underlined mode
o -v, --version Display version and exit
Calling set_color normal will set the terminal color to whatever is the default color of the terminal.
Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey
font color, while set_color --bold white will result in a white font color.
Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator.
set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and
incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of
ncurses and recompile fish against it in order to fix this issue.
Version 1.23.1 Sun Jan 8 2012 set_color(1)