General :: Bash Function/alias For Package Managers?
Jul 6, 2010
I have packer installed for AUR packages, but I want to be able to use the pacman command for both. I think I will need a function for this -- what I mean is that whenever I use pacman, it will try using packer and if that fails (invalid option) it will use pacman-color. It could also decide which program to use based on the arguments. I can't just use packer (alias pacman='sudo packer') because packer doesn't have some options like -R to remove packages. I want to always use it to install and upgrade packages however, because It can install from the default repositories as well as AUR.
Does someone know how to accomplish this, or could point me in the right direction? I'm new to bash scripting. error (e.g. pacman -V prints packer: Option '-V' is not valid.).
I have trouble with using an alias inside aash function. I would like to ssh into multiple machines by executing:ssh machine To achieve this, I put something like the following into my ~/.bashrc:
This should be a simple thing to accomplish, but I can seem to figure it out. Essentially, I want to have a bash alias or function that will let me recursively grep the current directory. A while back I added this to my .bashrc:
Code:
alias rg="grep -r --exclude=*/.svn/* --exclude=*.swp"
This works fine, (and also ignores any svn and vim swp files), and I can call it like:
Code:
rg foo *
However, 99.999% of the time, I am only interested in searching in the current directory, so the "*" is a bit redundant. Also, I would say 5-10% of the time, I am typing faster than thinking and forget the "*", so grep just sits there trying to read from stdin. It's a pretty minor thing, but ideally I'd like to be able to just type:
Code:
rg foo
I've tried creating a function to handle this:
Code:
function rg(){ grep -r --exclude=*/.svn/* --exclude=*.swp $1 * }
but it behaves exactly the same as the alias above. escaping the "*" with 's doesn't work, and neither does trying `pwd` (or even a hard-coded path) in its place.
I have a noob qn, if I installed a program with yum, will I be able to see the details of the installed program with rpm -qa? My linux has no internet access so I can't test it out.
I've been looking further into Linux from Scratch, and I am particularly interested in the package management side of the system. I understand that this is not covered in the book, but if I were to attempt LFS, package management would be a major convenience. From what I have read, when upgrading packages like glibc, you have to recompile everything to reflect the change.
If that is true, how do package managers like pacman and apt get around this issue? Isn't lacking glibc for even the time it takes to replace the files catastrophic to the system?
Is there an easier way (without using a package manager) to upgrade programs? For example, I just want to upgrade Amarok. In order to do this, I've had to upgrade every one of it's dependencies because they've all had minor upgrades from the versions I already have installed.
Is there an easier way to compile programs and their dependencies manually or are package managers the only way?
I know that using alias I can run a whole command with a shortcut. But my requirement is to use parts of a long command and in between I have to pass some user defined values. E.g. Suppose I have to routinely copy a directory to another remote directory on a remote machine.The remote machine name is quite long as well as the directory path to which I want to copy the files into.So the command to do scp would look like this[URL]Now I want to do some sort of aliasing (say "ecp") so that I just need to pass the source_directory name and the ecp command and do my job
I want to create an alias or function that when used prints something like this on the command line so I can further modify it before pressing enter myself.
Code: $ FILE=exercise1; cc -o $FILE $FILE.c && ./$FILE; FILE= The idea is that I'm studying c and want to change the name of the file once instead of
My problem is whit the package managers all of it is not responding (update,GDebi,synaptic), it bater if any one know application replacing them because i'm always having problem whit them and this picture could help ;
All my package managers are crashing. I will try to start them up, they will begin loading, and then will crash. The problem began with the Update Manager putting up the red circle error icon that says: "An error has occured, please run Package Manager from the right-click menu or apt-get in a terminal to see what is wrong. The error message was: 'Error: BrokenCount > 0'. This usually means that your installed packages have unmet dependencies."
The recommended fix for this looks to be on this post that I got from LaunchPad: [url]
It says to: "Open the Synaptic package manager. System --> Administration --> Synaptic Package Manager
If anything is broken it will tell you.Choose 'Custom' from the buttons at the bottom then click on 'Broken'
Right click on the offending package and choose to remove it."
If you set or export an environment variable in bash, you can unset it. If you set an alias in bash, you can unalias it. But there doesn't seem to be an unfunction.
Consider this (trivial) bash function, for example, set in a .bash_aliases file and read at shell initialization.
function foo () { echo "bar" ; }
How can I clear this function definition from my current shell? (Changing the initialization files or restarting the shell doesn't count.)
I have been using kubuntu 10.04 for a while now and its working great. The main problem is that as far as I know it lacks a simplified package manager like ubuntu software center. Kpackagekit is fine as a synaptic replacement but searching for programs among all sorts of unrelated packages is very tiring. Are there any other options?
I had debian squeeze on my personal computer at home, 3 days ago i've upgraded it to the debian testing. last day i've installed virtualbox which i've gotten from virtualbox.org . today non of package managers work. an example of installing sumthin new with apt:
I don't know whats happening. the second i open either the update manager, add or remove programs, or the package manager tehy close instantaneously and when i click the button for updates on the top bar of my computer it shows a picture of a minus sign in a red circle. hwo can i fix this. i have ubuntu 9.04 and im trying to upgrade it and get new programs but it wont let me. ive tried the sudo get updates etc etc
I just started writing bash scripts and have a little question about the text editors. I now use gedit which I really like (don't like emacs for some reason), but I do miss some function for inserting/removing comment signs (in this case # for bash scripts) on a whole block of text. For example in Matlab you can simply mark a whole block and comment/uncomment all of it at once. Is this possible in gedit (via some plug-in or something?), or maybe in some other nice editor you can recommend?
I am trying to execute executable files in bash without adding ./ I know there must be an alias to add in .bashrc, that must be something like alias PATH=$PATH:. But this seems not to be working.
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash addelementtoarray() { local arrayname=$1
Code: #!/bin/sh #System commands and other configurable. IPT=/sbin/iptables IP6T=/sbin/ip6tables IPST=/usr/sbin/ipset MODP=/sbin/modprobe GET=/usr/bin/wget INT_NET=192.168.1.0/24 .....
I can find lots of tutorials in how to use if, then, else. However, how do I define a variable inside the function? SEE>> Code: for c in $ISO Also, am I using the 'test' command correctly( -/+ week as valid test)?
I wanted to make an alias with arguments (like in cshell) which is in bash done by functions. The function must simply perform a command (nedit), append the arguments from the cli and make it run in the background (adding &).
So here is the function in a naive attempt:
Code:
when using the command
Code:
Code:
How can i use arguments and still start it in background? In cshell it was like:
I have taken into count spacing of functions as a reason for not working. Can you get this function to work on your machine? quickfind () { find . -maxdepth 2 -iname "*$1*" }
It does not print the retired output but find . -maxdepth 2 -iname "*$1*" does work. What is wrong? quickfind () { f ind . -maxdepth 2 -iname "*$1*" ; }
If I run this from the command line I don't get an error but no output? I am not running this inside a script but from the command line. I want to be able to run any function () from the command line. I have more functions that I can't get to work? tt () { tree -pFCfa . | grep "$1" | less -RgIKNs -P "H >>> " }
I'm making a small script for searching and doing some operations with photos, but I'm kinda stuck on this little function:
Code:
function findallformat { prefix="" if [ $1 = -pre ] then
[code]....
That function should find for every file with a certain type; and you can specify a prefix using a "-pre" followed by the prefix that you want to search. The format should be "stackable", so you can use as many types that you want, without repeating the same function on the code.
Example: findallformat -pre IMG_ .JPG .CR2 #That should search files that start with "IMG_" and finishes with .JPG and .CR2. My problem it's that, when I try to use it on the script, it says "bash: syntax error near `token' unexpected `}'"
I was wondering if possible in bash for a variable to take the value of a function, I mean the function returns a value and a variable will take it. example:
I found a weather function for bash from searching google, and started to finesse it. This is what I have so far, any tips to finesse it even more?
Code: # Based on code by Crouse at www.bashscripts.org weather() { declare -a WEATHERARRAY WEATHERARRAY=('lynx -dump "[URL]?hl=en&lr=&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=weather+${1}&btnG=Search" | grep -A 18 -m 1 "Current:" | sed -e 's/^[ ]*//' | cut -d '|' -f 1-5 ') echo Weather for the zipcode of $1:$' ' ${WEATHERARRAY[@] } }
I want to set a key binding in bash for "history-search-backward" readline command to a combination of Control+some other key (I'm using 2 as an example), but I'm unable to do so. in fact, I'm unable to alter or add bindings to Control+key combinations.
After several tries my ~/.inputrc now looks like this
But it doesn't work and bind -p | grep "-2" gives nothing. If I try something without the control key:
I can search in the history by prssing the sequence C + - + 2.
bind -p gives control in C form, for example:
I've tried different formats in my inputrc:
But nothing works.
works if I press Escape followed by 2.
Setup: Fedora 11: Bash version 4.0.23(1) GNU Readline 5.2 (according to the man page)
the function terminates if no key is pressed for 10 consecutive seconds. I tried using the -t option as suggested in some forums, but my version of showkey doesn't have the option of changing the timeout. The options I get are:
-h --helpdisplay this help text -a --asciidisplay the decimal/octal/hex values of the keys -s --scancodesdisplay only the raw scan-codes -k --keycodesdisplay only the interpreted keycodes (default).
Is it possible to write a script to use this function and still keep the function active until an interrupt is recieved?