Alias is not working under Bourne Shell


 
Thread Tools Search this Thread
Operating Systems Solaris Alias is not working under Bourne Shell
# 8  
Old 11-03-2015
Hi, sea.
Quote:
Originally Posted by sea
Well, echo $SHELL will print the active shell.
...
I'm not sure what you mean by active shell. I think of the value of environment variable SHELL as the path of the login shell. Here are several invocations of shells and the value of variable SHELL:
Code:
vm-jessie ~ $ echo $SHELL
/bin/bash
vm-jessie ~ $ ksh
h ~ $ echo $SHELL
/bin/bash
h ~ $ zsh
\h $(eval "echo ${_MYPSDIR}") $ echo $SHELL
/bin/bash
\h $(eval "echo ${_MYPSDIR}") $ csh
% echo $SHELL
/bin/bash
% tcsh
vm-jessie:~> echo $SHELL
/bin/bash
vm-jessie:~> ps
  PID TTY          TIME CMD
12669 pts/0    00:00:00 bash
13606 pts/0    00:00:00 ksh
13608 pts/0    00:00:00 zsh
13609 pts/0    00:00:00 csh
13610 pts/0    00:00:00 tcsh
13615 pts/0    00:00:00 ps

It worked this way on Debian (as shown), CentOS, Fedora, Slackware, OS X.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 9  
Old 11-03-2015
Quote:
Originally Posted by sea
Well, echo $SHELL will print the active shell.
It doesn't, it prints the Shell environment variable which is set at login time to the user's default shell.
Quote:
If it is bash or sh, did you try:
Code:
shopt expand_aliases

This won't work with the Bourne shell which is what the OP is running. The shopt builtin is, unlike aliases, bash specific.
# 10  
Old 11-11-2015
What? ��
Shopt is bash specific and shall therefor not run in his bash?

Oh wait, bourne != bourne again.

But either way, i do not think he's using the 'right' SH, as it is located in /sbin.

What is the output of:
Code:
ls -l /sbin/sh

I always thought that shells are (only) in bin.

Anyway, how about writing a function, rather than an alias?
Hth

EDIT: Scratch that, didnt see its in Solaris section (was on mobile)

Last edited by sea; 11-11-2015 at 07:00 PM..
# 11  
Old 11-11-2015
Quote:
Originally Posted by jlliagre
Finally, "echo $SHELL", is also an incorrect way to identify what shell you are running, This command will tell you the user's default shell, i.e. the one defined in the passwd database.
No. The SHELL var, where used/understood just says what shell to use if needed (e.g. .a sub shell created from another process). Doesn't have to be the shell defined in user's passwd entry at all, in fact has better chance of being set by the shell itself.

What shell is running?

echo $0 might be the best hint. Or ps -p $$
# 12  
Old 11-11-2015
Jilliagre is right. E.g. bash sets SHELL to the user's default shell if not yet set.
The old Bourne shell does not do that, but these systems use the login program - that does it.
And you are right, too. Once SHELL is set (automatically or manually), many tools (e.g. shell-terminal) open this shell.
--
Traditionally /sbin contained statically-linked binaries. At that times /usr was a separate partition or even a separate disk. If /usr failed and the kernel could load from / then it was good to have statically linked tools under / , without the need of the /usr/lib/*.so
Indeed Solaris 9 and older have
Code:
% ls -l /bin/sh
-r-xr-xr-x   4 root     root       95480 Nov 19  2008 /bin/sh
% ls -l /sbin/sh
-r-xr-xr-x   2 root     root      306216 Nov 19  2008 /sbin/sh
% ldd /bin/sh
        libgen.so.1 =>   /usr/lib/libgen.so.1
        libsecdb.so.1 =>         /usr/lib/libsecdb.so.1
        libnsl.so.1 =>   /usr/lib/libnsl.so.1
        libc.so.1 =>     /usr/lib/libc.so.1
        libcmd.so.1 =>   /usr/lib/libcmd.so.1
        libdl.so.1 =>    /usr/lib/libdl.so.1
        libmp.so.2 =>    /usr/lib/libmp.so.2
        /usr/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
% ldd /sbin/sh
ldd: /sbin/sh: file is not a dynamic executable or shared object

For each fix in one of the shared libraries Sun had to provide a new /sbin/sh (to also contain the fix). This was cumbersome.
Solaris 10 changed to
Code:
% ls -l /bin/sh
lrwxrwxrwx   1 root     root          13 Nov  7  2011 /bin/sh -> ../../sbin/sh

And in Solaris 11 Oracle has given up the Bourne shell
Code:
% ls -l /bin/sh
lrwxrwxrwx   1 root     root           9 Jun 17  2013 /bin/sh -> i86/ksh93
% ls -l /sbin/sh
lrwxrwxrwx   1 root     root          16 Jun 17  2013 /sbin/sh -> ../bin/i86/ksh93

This User Gave Thanks to MadeInGermany For This Post:
# 13  
Old 11-11-2015
I always thought /sbin to be the "/superuser binaries".
Or is this solaris specific?
# 14  
Old 11-11-2015
The primary purpose of /sbin is system recovery. Of course it is used by the "superuser".
Following that sense /usr/sbin was created with further "superuser" tools (dynamically linked).
BTW Solaris 11 has
Code:
% ls -ld /sbin
lrwxrwxrwx   1 root     root          10 Jun 17  2013 /sbin -> ./usr/sbin

And all Solaris have
Code:
ls -ld /bin
lrwxrwxrwx   1 root     root           9 Jun 17  2013 /bin -> ./usr/bin

Now even RHEL 7 joins in - what a relief!
The /bin /usr/bin /sbin /usr/sbin "quadriga" is quite common in Unix,
Portable shell scripts should start with
Code:
PATH=/bin:/usr/bin:/sbin:/usr/sbin

and then use simple commands.
I have seen a thousand scripts that have adventurous workarounds (e.g. manually trying each command with various pathnames, storing them in variables or even in arrays - disgusting!).
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Lost with this alias why it is not working

Hi, I have the following aliases: $: alias | grep "^du=" du='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn' $: alias | grep "^dutop10=" dutop10='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn | head... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

For loop in bourne shell is not working

I have a loop with cases I am working on Bourne shell for file in *.${Today}*.csv *.${Today}*.txt\ do case ${file} in sun_detail) do something ;; sum) do something ;; mod) do something ;; *) do something ;; (5 Replies)
Discussion started by: digioleg54
5 Replies

3. Shell Programming and Scripting

Alias not working

I have several shell scripts which contain the nawk command. Here is what i m doing assign the correct value to nawk as nawk is not found on a new systems. Here is what i did. more test.sh ] && alias nawk=/usr/bin/gawk ] && alias nawk=/usr/bin/nawk ] && alias nawk=/usr/bin/awk... (7 Replies)
Discussion started by: mohtashims
7 Replies

4. Solaris

Alias not working

Hi, I'm on Solaris (SunOS wsp2cm01 5.10 Generic_150400-10 sun4v sparc SUNW,Sun-Fire-T200). Trying to set up an alias like below - alias grep="/usr/xpg4/bin/grep"but when I call grep in my command it ignores my alias & uses /usr/bin/grep instead. The problem with /usr/bin/grep is that it doesn't... (24 Replies)
Discussion started by: nexional
24 Replies

5. Red Hat

[SOLVED] How the alias is working?

Iam facing some strange issue with alias. I have an alias file in which i have created lot of aliases as given below. export BUILD_HOME=/apps/psr/build export DB_HOME=/apps/psr/database export LOGS_HOME=/apps/psr/logs export BUILD_TEST=/apps/psr/build_dev/build_test export... (0 Replies)
Discussion started by: Vikram_Tanwar12
0 Replies

6. AIX

Alias Command in Bourne Shell

Hi My Unix sever is AIX 5.3. My Login shell ( using echo $SHELL) is /bin/sh implying it is a Bourne Shell. My Question is that i am still able to use Alias command to create/retrieve aliases. I have read in several sites on Unix online that the Bourne Shell does not support Aliases but... (12 Replies)
Discussion started by: pchegoor
12 Replies

7. Solaris

Alias not working

Hello, I am trying to set an alias in my .kshrc or .profile and when I do it is not setting. If I do it manually it works fine. Is there another file I should put this in? Here is the alias I am using. alias ll='ls -ltr' I am using solaris 9. When I type alias it does not show these... (5 Replies)
Discussion started by: dkranes
5 Replies

8. UNIX for Dummies Questions & Answers

alias not working in scripts

Hi All, PF below details, > cat run.sh #!/usr/bin/ksh alias ll="ls -l" > ./run.sh > ll ksh: ll: not found. Pls help on this? Thanks in Advance, Naga :cool: (2 Replies)
Discussion started by: Nagapandi
2 Replies

9. Shell Programming and Scripting

Bourne: How to invoke an alias from within a shell script

Bourne: How to invoke an alias from within a shell script If I type in the alias in the command line, it runs If I insert that same alias into my shell script and run the shell script, the alias is not invoked. Help please. (2 Replies)
Discussion started by: techshots
2 Replies

10. Shell Programming and Scripting

bourne shell not working

This code has worked for years and still does in my production environment. But it's failing in my development environment now. The cd works but the creation of node1, jnum, and node2 fails. Oddly the output shows a line from from the awk script at the end of the code during the setting of each... (6 Replies)
Discussion started by: gillbates
6 Replies
Login or Register to Ask a Question