Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-17-2013, 09:29 AM   #1
LQ Newbie
Registered: Sep 2010
Posts: 18

Rep: Reputation: 0
.bash_profile alias does not work in shell script

I have the following alias in my ~/.bash_profile

alias rdseed=/usr/local/rdseedv5.3.1/rdseed.mac.x86_64

When I call for rdseed in the terminal it works fine. However, when I call for it within a shell script I get the following error;
"rdseed: command not found"

When I add the exact line I have in my .bash_profile to the shell script and call it within the same script, it works fine.

All other aliases I have in my .bash_profile works within a shell script without any problem. I am baffled. Any suggestions? Thanks!

I am on MAC OS X (mountain lion)
Old 10-17-2013, 10:09 AM   #2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,127
Blog Entries: 14

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
How are you running the script? Are you logging in then running it or is it running in background tool like cron?

In the former case your script should inherit your login environment (e.g. everything set in .bash_profile, /etc/profile or others)
Prior to running the script if you run "alias" does it in fact show the defined alias?

In the latter case you get a minimal environment (that is to say it does NOT run invoke .bash_profile and other things) so you don't get those. This includes aliases AND variables such as PATH. Since you are specifying the full path to the command in your alias that probably isn't the issue but the fact that defining it works may be.

Also you might want to insure your first line of script is invoking the shell you expect.
Old 10-17-2013, 10:47 AM   #3
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
scripts don't expand aliases and don't bring in the current environment. so in script, after shabang, add this 'shopt -s expand_aliases'
shopt -s expand_aliases
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script: can you tell if a script is called via an alias? BrianK Programming 11 10-01-2009 12:16 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM
alias does not work in shell script mannahazarika Programming 9 01-20-2006 02:56 PM
alias does not work until ". .bash_profile" pcoveney100 Linux - Software 4 06-04-2004 10:17 PM
.bash_profile alias doesn´t seem to work Electronkz Linux - Newbie 2 04-11-2004 04:17 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration