Alias is not working under Bourne Shell


 
Thread Tools Search this Thread
Operating Systems Solaris Alias is not working under Bourne Shell
# 1  
Old 11-02-2015
Alias is not working under Bourne Shell

Hi,

Please assist me why HC alias is not working under this shell?

Code:
root@singapore # grep HC /.profile
alias HC='cd /var/tmp/HC/2015/`date +%B`'
root@singapore # . /.profile
Sourcing //.profile-EIS.....
root@singapore # echo $HC

root@singapore # HC
HC: not found
root@singapore # echo $SHELL
/sbin/sh
root@singapore # uname -a
SunOS singpapore 5.10 Generic_147440-19 sun4v sparc SUNW,SPARC-Enterprise-T5120

But, it works when I read the users profile:


Code:
root@singapore # bash
root@singapore # HC
bash: HC: command not found
root@singapore # . .profile
Sourcing //.profile-EIS.....
root@singapore # HC
root@singapore # pwd
/var/tmp/HC/2015/November
root@singapore #


Last edited by Don Cragun; 11-02-2015 at 04:48 AM.. Reason: Add CODE tags.
# 2  
Old 11-02-2015
Have you tried to execute in command line first to see?
Code:
alias HC='cd /var/tmp/HC/2015/`date +%B`'
 HC

What do you get?
This User Gave Thanks to vbe For This Post:
# 3  
Old 11-02-2015
The first you seem to run unser sh, the second under bash. What be the results of alias HC in either?
# 4  
Old 11-02-2015
Solaris /bin/sh does not have aliases.
Either have a function in .profile
Code:
HC() {
  cd /var/tmp/HC/2015/`date +%B`'
}

Or have the alias (or the function) in .bashrc, that is run when you start a bash.
# 5  
Old 11-02-2015
Quote:
Originally Posted by vbe
Have you tried to execute in command line first to see?
Code:
alias HC='cd /var/tmp/HC/2015/`date +%B`'
 HC

What do you get?
Code:
root@singapore # HC='cd /var/tmp/HC/2015/`date +%B`'
root@singapore # echo $HC
cd /var/tmp/HC/2015/`date +%B`
root@singapore # alias  HC='cd /var/tmp/HC/2015/`date +%B`'
root@singapore # echo $HC
cd /var/tmp/HC/2015/`date +%B`
root@singapore # echo $SHELL
/sbin/sh

---------- Post updated at 09:49 AM ---------- Previous update was at 09:48 AM ----------

Code:
root@singapore # HC='cd /var/tmp/HC/2015/`date +%B`'
root@singapore # echo $HC
cd /var/tmp/HC/2015/`date +%B`
root@singapore # alias  HC='cd /var/tmp/HC/2015/`date +%B`'
root@singapore # echo $HC
cd /var/tmp/HC/2015/`date +%B`
root@singapore # echo $SHELL
/sbin/sh

# 6  
Old 11-03-2015
Read MadeInGermany answer, aliases are simply not supported by the legacy Bourne shell which predates functions. There is no point trying to define and execute an alias under /sbin/sh or /bin/sh when running Solaris 10 and older.

In any case, to see what an alias contains, echo is the wrong command, as RudyC already posted, you simply use the alias builtin too (when supported by the shell).

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.
This User Gave Thanks to jlliagre For This Post:
# 7  
Old 11-03-2015
Well, echo $SHELL will print the active shell.
I get different results whether i type that inside a zsh bash or sh script, but in the terminal, usualy you are right, it prints the default shell, since most ppl dont change the terminal its shell.

If it is bash or sh, did you try:
Code:
shopt expand_aliases

hth
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