LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-17-2013, 08:29 AM   #1
januka
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, 09:09 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,911
Blog Entries: 14

Rep: Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142Reputation: 1142
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, 09:47 AM   #3
mddnix
Member
 
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'
Code:
#!/bin/bash
shopt -s expand_aliases
 
1 members found this post helpful.
  


Reply


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 11:16 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
alias does not work in shell script mannahazarika Programming 9 01-20-2006 01:56 PM
alias does not work until ". .bash_profile" pcoveney100 Linux - Software 4 06-04-2004 09:17 PM
.bash_profile alias doesn´t seem to work Electronkz Linux - Newbie 2 04-11-2004 03:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:05 AM.

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