Alias problem

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
sehoonha

Alias problem

Post by sehoonha »

Hi,

I using Linux Mint 17 that is upgraded from Linux Mint 16.
I tried to set aliases as usual, but it goes very wrong :(

This is ".bash_profile" in my home directory
=======
alias install='sudo apt-get install'
=======
It is just a single line, very simple.
But if I typed "alias" to check aliases, it goes totally wrong.

=======
sehoonha@constantinople ~ $ alias
alias grep='grep --colour=auto'
'lias install='sudo apt-get install
alias ll='ls -al'
alias ls='ls --color=auto'
=======

See? How can possibly an entry starts with 'lias?
Of course, if I type install....

=======
sehoonha@constantinople ~ $ install
[sudo] password for sehoonha:
E: Invalid operation install
=======

If someone could help me to resolve this problem, I will really appreciate...
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Habitual

Re: Alias problem

Post by Habitual »

Code: Select all

alias install='sudo apt-get install' 
then exit the editor and type in shell:

Code: Select all

source .bash_profile
then type install <package>
enter sudo password and ta da!

you can always check your aliases with

Code: Select all

alias <alias_name>
or

Code: Select all

type <alias_name>
sehoonha

Re: Alias problem

Post by sehoonha »

Thanks for your kind response.

But the problem is that aliases are messed up only when it is *automatically* loaded from .bashrc.
Habitual

Re: Alias problem

Post by Habitual »

sehoonha wrote:Thanks for your kind response.

But the problem is that aliases are messed up only when it is *automatically* loaded from .bashrc.
Show us your .bashrc then.

I usually create aliases directly in .bashrc or use

Code: Select all

source /path/to/another/alias/file
in .bashrc

Remove any alias causing issue from .bash_profile
and move it somewhere else, either in .bashrc or a new file and source it in .bashrc
I use .aliases (one of many such files) like so:

Code: Select all

grep aliases .bashrc | grep source
source /home/jj/.aliases
and in it are such things as:

Code: Select all

alias stampl="date '+%a %b %d, %Y - %l:%M:%S %p %Z'" # original date/time stamp
alias stamp="date '+%a %b %d, %Y'"

alias ipcalc='ipcalc -b'
alias cal='cal -3'
alias ip="curl icanhazip.com"
alias heat="sensors -f" 
Your alias is probably being 'stepped on' by another alias of similar definition.
in your ~ (home) directory type this:

Code: Select all

grep -w apt-get" .*  | grep -v .bash_history

or

Code: Select all

alias | grep install
What shows up?

You can test aliases with putting them anywhere by using a "--norc option in bash with

Code: Select all

bash --norc
then type

Code: Select all

alias install="sudo apt-get install"
right in the shell.

Verify by typing

Code: Select all

alias install
you should see

Code: Select all

alias install='sudo apt-get install'
test it directly with
install <some_program>

Let us know...

Once it behaves as expected in the "bash --norc" environment, then move it to either .basrhrc
or another sourced file from .bashrc

NOTE: I declared this same alias like

Code: Select all

alias install="sudo apt-get install"
but when I check it, it shows up as

Code: Select all

alias install='sudo apt-get install'
sehoonha

Re: Alias problem

Post by sehoonha »

In fact, as I stated, a single line of "alias install='sudo apt-get install'" is all of my .bashrc.
And the following is the result that I checked by typing "alias"

====
'lias install='sudo apt-get install
====

Of course, if I directly type " alias install='sudo apt-get install' ", it worked very well as usual.
Habitual

Re: Alias problem

Post by Habitual »

show us your ~/.bash_profile please.
sehoonha

Re: Alias problem

Post by sehoonha »

I have ~/.profile, which is following

Code: Select all

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
WharfRat

Re: Alias problem

Post by WharfRat »

Does this return anything :?:

Code: Select all

grep -w lias  ./.*
sehoonha

Re: Alias problem

Post by sehoonha »

Code: Select all

sehoonha@constantinople ~ $ grep -w lias  ./.*
grep: ./.: Is a directory
grep: ./..: Is a directory
./.bash_history:grep -w lias  ./.*
./.bash_history:grep -w lias  ./.*
grep: ./.cache: Is a directory
grep: ./.cinnamon: Is a directory
grep: ./.config: Is a directory
grep: ./.dbus: Is a directory
grep: ./.dotfiles: Is a directory
grep: ./.dropbox: Is a directory
grep: ./.dropbox-dist: Is a directory
grep: ./.dropbox-master: Is a directory
grep: ./.emacs.d: Is a directory
grep: ./.gconf: Is a directory
grep: ./.gimp-2.8: Is a directory
grep: ./.gnome: Is a directory
grep: ./.gnome2: Is a directory
grep: ./.gnome2_private: Is a directory
grep: ./.linuxmint: Is a directory
grep: ./.local: Is a directory
grep: ./.mozilla: Is a directory
grep: ./.pki: Is a directory
grep: ./.semanticdb: Is a directory
grep: ./.smartgit: Is a directory
grep: ./.speech-dispatcher: Is a directory
grep: ./.subversion: Is a directory
grep: ./.thumbnails: Is a directory
grep: ./.Trash: Is a directory
sehoonha@constantinople ~ $ 
WharfRat

Re: Alias problem

Post by WharfRat »

What about

Code: Select all

grep -w alias  ./.*
sehoonha

Re: Alias problem

Post by sehoonha »

Code: Select all

sehoonha@constantinople ~ $ grep -w alias  ./.*
grep: ./.: Is a directory
grep: ./..: Is a directory
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias make=
./.bash_history:alias
./.bash_history:alias make=make -j4
./.bash_history:alias
./.bash_history:alias make='make -j4'
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias --help
./.bash_history:alias p
./.bash_history:alias -p
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:locate alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bash_history:alias
./.bashrc:alias install='sudo apt-get install'
grep: ./.cache: Is a directory
grep: ./.cinnamon: Is a directory
grep: ./.config: Is a directory
grep: ./.dbus: Is a directory
grep: ./.dotfiles: Is a directory
grep: ./.dropbox: Is a directory
grep: ./.dropbox-dist: Is a directory
grep: ./.dropbox-master: Is a directory
grep: ./.emacs.d: Is a directory
grep: ./.gconf: Is a directory
grep: ./.gimp-2.8: Is a directory
grep: ./.gnome: Is a directory
grep: ./.gnome2: Is a directory
grep: ./.gnome2_private: Is a directory
grep: ./.linuxmint: Is a directory
grep: ./.local: Is a directory
grep: ./.mozilla: Is a directory
grep: ./.pki: Is a directory
grep: ./.semanticdb: Is a directory
grep: ./.smartgit: Is a directory
grep: ./.speech-dispatcher: Is a directory
grep: ./.subversion: Is a directory
grep: ./.thumbnails: Is a directory
grep: ./.Trash: Is a directory
sehoonha@constantinople ~ $ 
WharfRat

Re: Alias problem

Post by WharfRat »

Call the alias something else, it might be due to the /usr/bin/install file
WharfRat

Re: Alias problem

Post by WharfRat »

WharfRat wrote:Call the alias something else, it might be due to the /usr/bin/install file
@ sehoonha,

I tried the same alias as you and it worked. Are you sourcing anything in /etc/profile, /etc/profile.d/, /etc/bash.bashrc, ~/.bash_profile, ~/.bash_login, ~/.bashrc or ~/.profile :?:

This is certainly odd :?
Habitual

Re: Alias problem

Post by Habitual »

Code: Select all

locale
maybe?
Locked

Return to “Scripts & Bash”