Not able to create alias in bash Sun solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to create alias in bash Sun solaris
# 1  
Old 07-13-2012
Not able to create alias in bash Sun solaris

Hello Friends,

I am facing problem in creating aliases.

I am working in SunOS 5.10. When I login in system i have been given ksh shell.

What i am doing is that ?

I am changing shell to bash then I am creating 2 alias in command prompt like:
Code:
alias deploy_dir=' cd /opt/home/deploy/'
alias log_dir=' cd /opt/home/javalogs/'

It is working fine in command prompt. But when kept these 2 cmds in shell script and executed it gives error like:
myalias.sh:
Code:
#!/bin/bash
alias deploy_dir=' cd /opt/home/deploy/'
alias log_dir=' cd /opt/home/javalogs/'

Scripts run successfully but when i tried to type:
bash-3.00$ deploy_dir
bash: deploy_dir: command not found
bash-3.00$ log_dir
bash: log_dir: command not found

Please suggest what is wrong?

Thanks
Krsna
# 2  
Old 07-13-2012
Hi

You should source the script, not run the script like a command.

if in bash:
Code:
$ source script_name

for ksh:
Code:
 . scriptname

Moreover, the script may not help you much since the default shell is ksh.

i) do not put the #!/bin/bash line in the script
ii) since the default is ksh, run the script like:

Code:
  . scriptname

Guru
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 07-13-2012
Hi Guru,

Many thanks, it is resolved by your solution. I have question for my understanding..

1. using
Code:
source

means we are running script in same shell. Generally what should be right way to run script, in same shell or in parent shell?

2. If i need to run script usng bash then why can i not put . As i can see one the vendor provided script we have which start the tomcalt server using this entry...
Code:
#!/bin/bash

we run that using ./starttomcat.sh..

Thanks..
# 4  
Old 07-13-2012
Hi

1) When you have a script which contains commands like aliases or setting environment variables, we usually want them to get reflected in the current shell. In these cases, we use source. This is why always the profile files and aliases are run using the . or source.

2) If you put the shebang(#!/bin/bash) in the script, you are telling the OS to run the script using the shell mentioned in the first line (which in this case is bash). The moment this happens, your aliases are not going to work since this is not run in the same shell. Moreover, alias syntax is not the same across all shells. In case of your vendor script, it is just like any other shell script, not some shell specific settings, which is why the shebang line is present.

Hope this helps.

Guru
# 5  
Old 07-13-2012
Great ,

Thank you so much..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

2. Shell Programming and Scripting

Create an alias

I want to create an alias cpage4 and create a postscript file For example I want to call cpage4 file.f which creates the file file.ps I have written like this but don't know how to continue alias cpage4 '/usr/bin/mpage -m40 -4AHP- \!* (6 Replies)
Discussion started by: kristinu
6 Replies

3. Solaris

Create Unix printer in sun Solaris

Guy's Can anyone explain how to Create Unix printer in Solaris what's the exact steps to create Unix direct printer ? (3 Replies)
Discussion started by: Mr.AIX
3 Replies

4. Shell Programming and Scripting

linux bash script to sun solaris

Hi guys, I seek a solution for this action for Sun solaris. find /sapmnt/${up}/global -prune -printf "%m %M %u %g %p\n" > $DAT1 The Application/Utilities in Sun Solaris are to old and cant understand "-printf". An update for Application/Utilities is exist, but not possible to implement... (6 Replies)
Discussion started by: ixibits
6 Replies

5. Shell Programming and Scripting

Need to create an ALIAS....

Hi GUYS, I need to create an alias for the the connect statement. I want to replace "CONNECT TO DBNAME" to "CONNECT TO DBNAME user USERID using PASSWORD" I thought i will add an alias in the .profile. But its not working. May be because i am trying to create it for 3 words instead of one... (2 Replies)
Discussion started by: mac4rfree
2 Replies

6. UNIX for Dummies Questions & Answers

Create Alias on Desktop

Hi, I just need a simple UNIX command to send out over ARD that will create an alias to an application and place it on the desktop. Thanks (0 Replies)
Discussion started by: yodomino6
0 Replies

7. UNIX for Dummies Questions & Answers

Sun Solaris 10: How do I create a bootup disc? The Sun website confuses me

Hey there, I am starting a Computer Science Foundation year at the end of this month and am trying to get a little bit ahead of the game. I have always wanted to learn Unix and am currently struggling with creating a boot disc to run Solaris (I have chosen to study this) from as opposed to... (0 Replies)
Discussion started by: Jupiter
0 Replies

8. UNIX for Dummies Questions & Answers

How to create a alias with an argument

If I want to create an alias called "cdr", and this alias need an argument (for example arg1)followed by "cdr", the result should go to the directory like "/home/ting/arg1/report/logs", the command should look like below, alias cdr arg1 "cd /home/ting/\!$1/report/logs" (not working)::( ... (1 Reply)
Discussion started by: ting123
1 Replies

9. Solaris

Can i create pcfs partition using sun solaris 10 ?

Can i use the sun solaris 10 to create Fat32 partition ? and i have another question im so confused between format command an fdisk within it, and mkfs and newfs, well what i got is that i have to use format to create partition physcially in my hard disk then i have to use mkfs or newfs (which is a... (2 Replies)
Discussion started by: XP_2600
2 Replies

10. Programming

Create an alias

I want to create an alias that will grep the passwd file for the logged in persons username and then it will return the password file entry. I want to pipe the whoami info to the grep command. I have created the following: % alias whopw grep... (1 Reply)
Discussion started by: mozark
1 Replies
Login or Register to Ask a Question