LinuxQuestions.org
Review your favorite Linux distribution.
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 12-27-2014, 05:43 AM   #1
Paolopd
Member
 
Registered: Mar 2010
Distribution: Debian Jessie/Xfce4
Posts: 39

Rep: Reputation: 0
Alias and its use


Hi guys!
I have a simple question.
I wolud like to make an alias just for update and upgrade the system evrytime I use it.
I have tried this, but it doens't work at all:
Code:
alias uu='aptitude update && safe-upgrade'
The system gave me back this:

Code:
Oki@debian:~$ alias uu='aptitude update && safe-upgrade'
Oki@debian:~$ uu
E: Impossibile aprire il file di blocco /var/lib/apt/lists/lock - open (13: Permesso negato)
E: Impossibile bloccare la directory /var/lib/apt/lists/
I think the problem is due to the fact that I should to set "sudo" and "sudo password", but I don't know how to do this with alias.

Any help?

Thank and Happy Holidays
 
Old 12-27-2014, 06:01 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
You need to use visudo to configure sudo, to allow the user to use the command sudo.
also I would create a script, for example update.sh and put aptitude update && safe-upgrade in it.
finally you can create an alias uu='sudo /full/path/to/update.sh'
 
Old 12-27-2014, 02:43 PM   #3
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Code:
alias uu='aptitude update && safe-upgrade'
This doesn't actually mean anything. Single quotes ' indicate a string

Run the command with the quotes and you'll see it doesn't do anything.
You need double quotes instead

you're also using it without sudo when run.

Try this:
Code:
alias uu="sudo aptitude update && sudo safe-upgrade"
Or as a function
Code:
uu() { sudo aptitude update && sudo safe-upgrade; }

Last edited by Miati; 12-27-2014 at 02:46 PM.
 
Old 12-31-2014, 07:49 PM   #4
Paolopd
Member
 
Registered: Mar 2010
Distribution: Debian Jessie/Xfce4
Posts: 39

Original Poster
Rep: Reputation: 0
Happy new year to everyone!
But...I don't cook up anything that was written on many guides I found on the net.Please, can you give me more explanation why you use double quotes?
Thanks
 
Old 12-31-2014, 09:25 PM   #5
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Quote:
Originally Posted by Paolopd View Post
why you use double quotes?
Read through this link to gain a understanding of the usage of quotes

As you might know, && means to do command if the previous command suceeds. This means it is a special character that is interepted by the shell.
When it is in single quotes, the shell does not interpert it as a special character and processes it as a normal character.

Double quotes however will make some special characters stay normal and have others stay special.
I used double quotes because I wanted to alias to understand it as a command, but not break as would happen if you did this:
Code:
alias uu=sudo aptitude update && sudo safe-upgrade
This would result in uu being set as sudo and then aptitude would run with arguements update (not as sudo) and continue the rest of the command.
 
Old 01-02-2015, 11:23 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
see man page of bash, especially the aliases:
Quote:
Aliases allow a string to be substituted for a word
In your case the two lines will do exactly the same thing:
Code:
alias uu='aptitude update && safe-upgrade'
alias uu="aptitude update && safe-upgrade"
The main difference is (are): in post #3 sudo was also inserted and/or a function was created.
 
  


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
bash script to display alias commands and un-alias any less than 12 characters bani Linux - Newbie 5 01-19-2014 01:34 PM
LXer: alias.sh puts your Linux shell alias on the clouds LXer Syndicated Linux News 0 01-21-2013 01:00 AM
Wildcard email alias in /etc/alias file custangro Linux - Enterprise 1 10-02-2009 01:17 PM
IP alias? Machine name alias? JohnLocke Linux - Newbie 4 01-16-2008 01:21 PM
Alias question (2 commands for one alias) gflores Linux - Newbie 3 01-21-2006 01:40 AM


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