How to avoid multiple sudo commands in one-liners
We all love one-liners but soon one-liner like this will destroy the coolness of using oneliners
We all love one-liners but soon one-liner like this will destroy the coolness of using oneliners
sudo apt-get update && sudo apt-get upgrade -yThere is mechanism that allows to enter sudo once and sudo access without password remains for a few minutes which is great for tasks that dont require a lot of time but still the repetition makes it look ugly! but there is a very cool way to over come this!
Use Here strings
A here string in bash is a type of redirection that allows a string to be passed (<) to standard input (stdin) of a command. It is denoted by a << followed by a delimiter that is used to identify the end of the string. The string can span multiple lines and can contain variables and special characters. This means that we can redirect all commands to sudo at once!
Example: one line
This command will ask for sudo once, which makes the command sorter since we dont repeat the sudo command
$ sudo -s <<< 'apt update -y && apt upgrade -y'Example: Command span in many lines
In case that the commands span in multiple lines we can do the following, pressing enter after the first command will not execute the command, will wait for the commands to end with the ' character to execute them
$ sudo -s <<< 'apt update -y
> apt upgrade -y'Conclussion
I hope you liked this simple trick! i always like to use tricks that can increase productivity and make my life easier! you?