LinuxQuestions.org
Visit Jeremy's Blog.
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 07-11-2013, 02:32 AM   #1
xeechou
Member
 
Registered: Jun 2013
Location: China
Distribution: Archlinux
Posts: 67

Rep: Reputation: Disabled
why cant ai use alias in my own script


I set
Code:
alias ll="ls -l"
in ~/.bashrc but when I wrote my own script, I just can't use it anyway. Well, it turns out that the issue I met is about subshell etc. Then I tried to wrote
Code:
. ~/.bashrc
and
Code:
alias ll="ls -l "
, still, it doesn't work. It is too weird.
I do still not clear about concept of shell, subshell, If /bin/bash is a shell, then I do really fell confused about difference between shell and program
 
Old 07-11-2013, 03:18 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,516

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
You might need to explain again as I cannot follow what your issue is?

You mention a script in the title but there is no mention of it after that or where you are calling 'll'?
 
Old 07-11-2013, 03:31 AM   #3
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 525

Rep: Reputation: 141Reputation: 141
Thats because shell scripts
  • don't expand aliases and
  • don't bring in the current environment

In script, after Sha-Bang, add this line:

Code:
shopt -s expand_aliases
Source: LINUX: Scripts and Alias
 
Old 07-11-2013, 03:33 AM   #4
xeechou
Member
 
Registered: Jun 2013
Location: China
Distribution: Archlinux
Posts: 67

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
You might need to explain again as I cannot follow what your issue is?

You mention a script in the title but there is no mention of it after that or where you are calling 'll'?
WEll, the script can be anything even if just a single line
Code:
ll /usr
the "ll" here is aliased to 'ls-l'
 
  


Reply

Tags
bash scripting


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
Works in alias, not in script lucmove Programming 1 09-24-2011 09:45 AM
Shell script: can you tell if a script is called via an alias? BrianK Programming 11 10-01-2009 11:16 AM
alias within a script lordofring Linux - Software 4 03-06-2006 02:49 PM
alias does not work in shell script mannahazarika Programming 9 01-20-2006 01:56 PM
alias not workin inside a script sanjith11 Programming 7 08-31-2005 03:36 PM

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

All times are GMT -5. The time now is 11:58 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