![]() ![]()
|
Hello, I think I got a great idea to make multi commands faster to write :
Instead of typing : sudo apt-get update && sudo apt-get full-upgrade && sudo apt-get install anApp && sudo apt-get install -f anApp2 && sudo apt-list update My idea would be to type : sudo {apt-get {update, full-upgrade, install {anApp, anApp2}}, apt-list update} Please someone code something like that. Thanks. |
![]() Registered Member ![]()
|
Just create some bash aliases. They are not hard to do.
claydoh, proud to be a member of KDE forums since 2008-Oct, and KDE user since 2001
|
![]() Global Moderator ![]()
|
And don't forget to source your bashrc after each change to apply your new settings.
Debian testing
|
![]() ![]()
|
I don’t know that bash aliases would work, since the way I suggested of doing bash must work will all commands and not with some of them. |
![]() Registered Member ![]()
|
You'd use a bash alias (or function or script) for any sequence of commands that you do repeatedly, so you could have something like updateAndInstall which takes the name of the package you want to install and then runs through those commands, updating the system and installing the given package.
Alternatively, you could use a for loop over the parameters you want to run: for param in update full-upgrade 'install app1 app2' do sudo $param; (I'm not familiar with the apt-list command or what purpose it serves; seems unnecessary; or is it just another example command that you want to tack to the end?) For much more than that, you might look into general bash scripting and just throw together your own bash script which works the way you want.
airdrik, proud to be a member of KDE forums since 2008-Dec.
|
![]() ![]()
|
In fact all of these commands was only examples. So they are all params. What I want to do is a new universal syntax for multi-commands bash. I mean instead of repeating part like "sudo" after each && why not do like in javascript? And apt-list is something made for listing all packages and what they are doing. |
![]() Registered Member ![]()
|
I think if you explore bash a bit more you'll find that there are ways of doing things like that in bash that aren't much less terse than what you are proposing. The suggestion that you could use a for loop over the commands you want to run is one way to do that. The idea to throw together your own scripts would allow the scripts to interpret the parameter syntax you want and then run the commands in the way you expect.
(btw, suggestions for changes to bash won't get very far here since bash is independent (part of GNU), and in fact I would guess that suggestions for changes to bash won't get very far at all since it is a very mature and well-established product that's used extensively, having been the default shell for the majority of linux (and bsd?) distros for the just about forever). You can also look into other shells like zsh, to see if any of them make things like this easier.
airdrik, proud to be a member of KDE forums since 2008-Dec.
|
![]() Registered Member ![]()
|
Hi, vrackfall
You can find how to write bash scripts here: https://www.polydesmida.info/BASHing/2018-07-18.html Now, let me try to explain you something: For example, you can find the history of your command typing on a terminal the following : history | grep update You could see at the left a number (for example 4432) with the last time you typed the command sudo apt-get update and then you can also type: !4432 and you get done with sudo apt-get update. I should recommend you not to type many command as you wrote, because you will be messed up. Keep it simple, stupid. sudo apt-get update && sudo apt-get full-upgrade && sudo apt-get install anApp && sudo apt-get install -f anApp2 && sudo apt-list update Kde has the PackageEdit Manager (pkcon) which brings both the latest kde and Ubuntu to update, and is very simple, type this command: pkcon refresh Afterwards, you want to install the updates and type pkcon update Then, before you want to install a package you could search which is available typing pkcon search package and for the installation pkcon install package Also, you can use the apt-get command to upgrade, list-upgradable, search and install packages. At last, whether you have problems to install a package you could see the pkcon manpage on a terminal window and, for exampel, you could type pkcon repair As you can see, to do things all in one shot something I could not always recommend. You must be sure to run multiple commands at the same time. Hope it help you |
![]() ![]()
|
Did someone at least understood what I was trying to show?
I mean that this kind of syntax with {} and , instead of && would work with every commands. This was only an example : sudo {apt-get {update, full-upgrade, install {anApp, anApp2}}, apt-list update} that could replace : sudo apt-get update && sudo apt-get full-upgrade && sudo apt-get install anApp && sudo apt-get install -f anApp2 && sudo apt-list update This could also be another example : copy -f fido.txt home/user/fido.txt && copy -f fido2.txt home/user/fido2.txt && rm -r -f home/user/dir2/ that could be replaced by : do {copy -f {fido.txt home/user/fido.txt, fido2.txt home/user/fido2.txt}, rm -r -f home/user/dir2/} |
![]() Registered Member ![]()
|
Yes, we understand what you are trying to show, you are proposing a change to the way bash works to invoke multiple commands in a more succinct manner than is currently required, by using curly-braces to indicate that you want the outer command invoked for each item inside the braces.
Keep in mind that bash is an independent project that already has it's own defined behavior for brace expansion (among other things). You can't just propose changes to something without understanding it first and how your proposed changes might impact other functionality of the project. As your proposed syntax conflicts with already defined syntax and as bash isn't under our control we aren't going to just go making changes to it. Instead, we've been proposing suggestions for other ways to accomplish what you want. They may not be as succinct as your proposed syntax, but they get the job done.
airdrik, proud to be a member of KDE forums since 2008-Dec.
|
![]() ![]()
|
I am not proposing this syntax for replacing the &&, but for work with it. For example, by creating an app for KDE that would recursively execute all commands as bash but from my fancy way. |
![]() Registered Member ![]()
|
Hi,
I will take this as a reference. The program name is actualizar.sh, once you have written the program change the permissions to 754 with sudo chmod 754 actualizar.sh #!/bin/bash # Program for running multiple commands UPDATE= apt-get update echo updating: $UPDATE ~ You can run this script with the command: sudo ./actualizar.sh Then, you can add multiple tasks on the scripts. Do you want to use brackets? I add below a program that tell you which programs are eating your CPU, which include brackets. #!/bin/bash #Name: pcpu_usage.sh #Description: Script to calculate cpu usage by processes for 1 hour SECS=3600 UNIT_TIME=60 #Change the SECS to total seconds for which monitoring is to be performed. #UNIT_TIME is the interval in seconds between each sampling STEPS=$(( $SECS / $UNIT_TIME )) echo Watching CPU usage... ; for((i=0;i<STEPS;i++)) do ps -eocomm,pcpu | tail -n +2 >> /tmp/cpu_usage.$$ sleep $UNIT_TIME done echo echo CPU eaters : cat /tmp/cpu_usage.$$ | \ awk ' { process[$1]+=$2; } END{ for(i in process) { printf("%-20s %s\n",i, process[i]) ; } }' | sort -nrk 2 | head rm /tmp/cpu_usage.$$ #Remove the temporary log file Try to see whether you can apply to your needs. Regards |
![]() Registered Member ![]()
|
Also aliases are helpful, see this post. The you open with vim, nano or any other text editor the archive .profile on your home/username folder and follow the instructions of this post: https://opensource.com/article/18/9/handy-bash-aliases Hope it helps, |
Registered users: Bing [Bot], Google [Bot]