LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-06-2010, 09:16 PM   #1
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 180

Rep: Reputation: 17
set alias in bash scripts


I tried this to set an alias:

alias lsf='ls -f'

and it works fine... But when I put it in a bash script it doesnt work.

SCRIPT:

cd ~
alias lsf='ls -F'
lsf

I get the following output:
line 3: lsf: command not found

Any ideas?
 
Old 09-06-2010, 10:07 PM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
From manpage of alias:
Quote:
An alias definition shall affect the current shell execution environment and the execution environments
of the subshells of the current shell. When used as specified by this volume of IEEE Std 1003.1-2001, the
alias definition shall not affect the parent process of the current shell nor any utility environment
invoked by the shell; see Shell Execution Environment .
and: http://www.opengroup.org/onlinepubs/...html#tag_02_12
 
Old 09-06-2010, 10:13 PM   #3
vonedaddy
Member
 
Registered: Aug 2004
Location: Philadelphia,PA
Posts: 180

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by quanta View Post
Thanks for that, after some searching I did it like this:

alias lsf='ls -F'
shopt -s expand_aliases
lsf

Which seemed to work for what I needed.
 
  


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
Where to set global alias? exitsfunnel Linux - General 9 07-29-2014 10:12 AM
[SOLVED] How to set permanent alias konzo Linux - Newbie 1 01-23-2010 11:03 AM
[SOLVED] Finding bugs in bash scripts, Analyis tool for bash traene Programming 2 10-31-2009 12:42 PM
How to set alias? thomas2004ch Linux - Newbie 5 08-05-2009 08:02 AM
How to set an IP alias in Kubuntu leupi Ubuntu 1 04-14-2006 12:26 PM


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