VectorLinux
April 23, 2014, 07:03:55 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1] 2
  Print  
Author Topic: alias command not working  (Read 4749 times)
varaahan
Member
*
Posts: 52


« on: September 15, 2007, 07:37:08 am »

I tried to create an alias for pppoe-start and pppoe-stop by editing .bashrc file of root but it is not working.
See this output:

"You are working as root
Frequently used programs:
Configuration  : vasm
Package manager: slapt-get
Network tools  : ifconfig, host, ping, nmap, iptables
File manager   : mc (press F2 for useful menu)
Editor         : mcedit, vi
Multimedia     : alsamixer, play
bash: alias: pon: not found
bash: alias: =: not found
bash: alias: pppoe-start: not found
bash: alias: poff: not found
bash: alias: =: not found
bash: alias: pppoe-stop: not found "

The relevant portions of .bashrc file is as follows:


#aliases for net connection
alias pon = "pppoe-start"
alias poff = "pppoe-stop"

Again I tried modifying them as follows:


#aliases for net connection
alias pon = "/usr/sbin/pppoe-start"
alias poff = "/usr/sbin/pppoe-stop"


And again I got the following msg:

bash: alias: pon: not found
bash: alias: =: not found
bash: alias: /usr/sbin/pppoe-start: not found
bash: alias: poff: not found
bash: alias: =: not found
bash: alias: /usr/sbin/pppoe-stop: not found.


Please advise.


Logged
lagagnon
Global Moderator
Vectorian
*****
Posts: 1922



WWW
« Reply #1 on: September 15, 2007, 07:49:31 am »

No spaces allowed in bash alias commands, I believe, so they should look like this:

alias pon="pppoe-start"          ...,


(see "man bash" and search for alias)
Logged

"As people become more intelligent they care less for preachers and more for teachers". Robert G. Ingersoll
varaahan
Member
*
Posts: 52


« Reply #2 on: September 15, 2007, 04:17:13 pm »

That makes no difference:


See the edited file (.bashrc) and the error msg:


#created for net connection
alias pon="/usr/sbin/pppoe-start"
alias poff="/usr/sbin/pppoe-stop"
bash: alias: pon: not found
bash: alias: =: not found
bash: alias: /usr/sbin/pppoe-start: not found
bash: alias: poff: not found
bash: alias: =: not found
bash: alias: /usr/sbin/pppoe-stop: not found


Logged
rbistolfi
Packager
Vectorian
****
Posts: 2265


« Reply #3 on: September 15, 2007, 04:31:39 pm »

At least in my box, alias works with ´´ but not with "", so

alias pon=´/usr/sbin/pppoe-start´

works. I think you still need to be root to run that command.
Logged

"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!
varaahan
Member
*
Posts: 52


« Reply #4 on: September 15, 2007, 05:08:53 pm »

Doing so didn't solve the issue.

In fact I have tried all the options / net but the problem persists.

VL has no man / info  entry for alias.
Logged
lagagnon
Global Moderator
Vectorian
*****
Posts: 1922



WWW
« Reply #5 on: September 15, 2007, 05:34:11 pm »

Nearly all sbin commands must be run as root. Are you trying to run from bash as a normal user? That might be your problem...
Logged

"As people become more intelligent they care less for preachers and more for teachers". Robert G. Ingersoll
Vxt
Member
*
Posts: 86


« Reply #6 on: September 15, 2007, 05:39:12 pm »

Normally ~ any new "alias"  will not work until session is  re-logged in

For immediate useage:
Code:
source ~/.bashrc

Likely   will need to be put into /root's home folder
(Distro specific "profile"
(source) may not work,   Esp if PAM exists (setuid lookup)

Unless user had permissions edited
 
(I.E. be part of limited priviledged group
Even a member of "wheel" group has  limited Sys/admin rights

As does (su)  versus (su -l)

The full path (to aliased commands) should not be needed
'bin' etal is part of normal root environment variable
 
Code:
env
  <-- OOPS, sorry  EDITED: from eXv to eNv
Code:
man export

AFAIK spaces are allowed in alias syntax
Single or double quotes are optional
As are curly braces for some text (otherwise parsed as non-terminated CLI expansion)
by each (legacy = varies)  shell interpreter
Pse notice - Each string in sample  was parsed as a command

(pon)  (=)

Bash did not recognise new aliased command 


 HTH
« Last Edit: September 15, 2007, 05:42:55 pm by Vxt » Logged
rbistolfi
Packager
Vectorian
****
Posts: 2265


« Reply #7 on: September 15, 2007, 05:45:15 pm »

VL has no man / info  entry for alias.

That is because alias is a built in bash command, may there is something in man bash.
It is working here, I edited my root .bashrc, exit and login as root again just to be sure the .bashrc file will be executed -or just run bash- and the alias is working. Check if .bashrc is executable, also you can check the output of the alias command with no arguments, it will return a list of current aliases.

EDIT: Vxt beat me to the punch
« Last Edit: September 15, 2007, 05:57:35 pm by rbistolfi » Logged

"There is a concept which corrupts and upsets all others. I refer not to Evil, whose limited realm is that of ethics; I refer to the infinite."
Jorge Luis Borges, Avatars of the Tortoise.

--
Jumalauta!!
Vxt
Member
*
Posts: 86


« Reply #8 on: September 15, 2007, 09:32:33 pm »


RB -

 Wink Sorry about that 

Errata: 

EXAMPLES

Alias is an optional 'variable command environment'

By itself is not a stand-alone executeable ~ must be followed  valid CLI
'function arguments' < that act upon text strings

This differs from  Parameters of commands
Plse see also (reserved characters)
&  (man unalias)

("man" bash Huh who the heck can wade thru 1675 + lines)
-------------------------------------------------------------------------------------------
Tested / Edited :  AKA trivia 

OK 'bashed'  this all to H - - -

Code:
# /etc/skel/.bash_profile

# This file is sourced by bash for login shells.
# The following line
# runs your .bashrc and is recommended by the bash info pages.

[[ -f ~/.bashrc ]] && . ~/.bashrc

#Sample bashrc
alias ls="ls --color=auto"
alias rm='rm -i'
alias cp="cp -i"

=  Double - quotation marks work

Whitespaces don't

(Hmm,  never fully tested b4 ~ Easier  && < faster  to type single quote (no key modifier)
Logged
Freston
Vectorite
***
Posts: 165


« Reply #9 on: September 16, 2007, 02:28:42 am »

It works fine on my box.

alias ll="ls -l" for example

And you don't have to be root to do so. Aliasses only work on the account they are defined in. As such, they are part of your user variables, so to speak. You do need permission over the command called. It's just a tool to safe you typing, nothing else. And no distro has a man page for alias, as it's part of the bash build in commands.

But why isn't it working? If you just try this:

alias hello="echo Good day"
and then type hello
It should work for as long as you are logged in to your current session.

Does it?




Oh, if you ever... and I mean this, if you ever type: <man bash | lpr>, then don't put the result near an open window :-( That will randomize some ~ 180 pages without page numbers.
« Last Edit: September 16, 2007, 02:35:09 am by Freston » Logged
varaahan
Member
*
Posts: 52


« Reply #10 on: September 16, 2007, 06:11:36 am »

Wow!
What a great participation!

I opened konsole terminal and did su and gave root password.
After editing /root/.bashrc file I logged out and then logged in as root.
In fact I restarted the machine but still could not succeed.
I vaguely remember using aliases in Mandrake some years back when it used to work fine.

Does it have something with Vector customization ?
Logged
Freston
Vectorite
***
Posts: 165


« Reply #11 on: September 16, 2007, 08:14:11 am »

Quote from: varaahan
Does it have something with Vector customization ?
Nope, works fine by me :-D

Have you tried the little test I posted?
Code:
alias hello="echo Good day"
and then type: hello
Don't su, dont put it in .bashrc. Nothing fancy. Just type it in the shell. Does it work? If that works, see below.
But wetter it works or not, post here what happens. It helps to pinpoint where the process goes 'wrong'.

Some more questions while we're at it. Does alias work when you enter them as user? As root?

---

On my user account I have to source .bashrc every time. I automated this by adding a flat file called ~/.bash_profile which contains -amongst others- the line <source ~/.bashrc>. I didn't have to do this in the root account, as bash seems to handle that by default. Yours doesn't seem to do this... That may have a logical explanation. But without knowing if the alias function works from the shell, I wouldn't know where to look.
Logged
varaahan
Member
*
Posts: 52


« Reply #12 on: September 16, 2007, 07:28:34 pm »

That works fine and see the output.


vector:/~
sridhar:$ echo "hello! Good day! "
hello! Good day!
vector:/~
sridhar:$ hello
-bash: hello: command not found
vector:/~
sridhar:$

Further I tested if there is an alias for rm:
sridhar:$ alias rm
-bash: alias: rm: not found

Then I created a file named test.txt


sridhar:$ kedit test.txt

and entered some text and checked it.
vector:/~
sridhar:$ cat test.txt
ahahahahvector:/~

And tried to create an alias for rm as follows:

vector:/~
sridhar:$ alias rm = "rm -i"
-bash: alias: rm: not found
-bash: alias: =: not found
-bash: alias: rm -i: not found


Undeterred I again ran and checked:

vector:/~
sridhar:$ alias rm='rm -i'
vector:/~
sridhar:$ alias rm
alias rm='rm -i'

And tested it :

vector:/~
sridhar:$ cat test.txt
ahahahvector:/~
sridhar:$ rm test.txt
rm: remove regular file `test.txt'? y
vector:/~
sridhar:$ 

Now it follows that Vector accepts (bash ?) = sign and single quote without spaces on either side.
But still this does not work in root's .bashrc file.



Logged
Freston
Vectorite
***
Posts: 165


« Reply #13 on: September 17, 2007, 02:35:04 am »

Oké, so bash is accepting aliases. That's good.

In bash syntax you're not supposed to use spaces. In csh on the other hand you do. Don't worry about that.

Next.
As a user, open up ~/.bashrc
Add a line like this:
alias ll="ls -l"
(I take this example because it's safe and useful  Wink)

Then type:
source ~/.bashrc

Then:
ll

What happens? If it works, do the same for /root/.bashrc

---

If you find that you need to <source ~/.bashrc> before you can use your defined aliases, then you can create a file to automate this. Just copy and execute the following in the shell:
Code:
echo "source ~/.bashrc" >> ~/.bash_profile
Do this for any account you want to use aliases in.
Logged
lagagnon
Global Moderator
Vectorian
*****
Posts: 1922



WWW
« Reply #14 on: September 17, 2007, 06:32:43 am »

But still this does not work in root's .bashrc file.

Works just fine here in root's .bashrc file. You must have either typed it in wrong, edited .bashrc incorrectly or did not reload a new bash session so that your newly edited .bashrc file was re-read.
« Last Edit: September 17, 2007, 06:42:08 am by lagagnon » Logged

"As people become more intelligent they care less for preachers and more for teachers". Robert G. Ingersoll
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!