Is it possible to create desktop shortcut, that would do as follows:
- open Terminal
- change directory
- make a command inside that directory
- type password (sudo)
I tried with Terminal profiles, but I didn't find option for 2. and 4.
First you need a script like one from the following example:
#!/bin/bash
commands () {
cd / # change directory, in this case to `/`
echo "your_password" | sudo -S mkdir -p "test" # execute a command as root for which the password is automatically filled
$SHELL # keep the terminal open after the previous commands are executed
}
export -f commands
gnome-terminal -e "bash -c 'commands'"
Don't forget to make the script executable!
Then, if you are not familiar about how to execute a script using a desktop shortcut, see Execute sh script from *.desktop file?.
echo "your_password"
- replace your_password
with your password; keep quotes and your password shouldn't contain another quotes. This command: mkdir -p "test"
will create a directory called test
in /
if there doesn't exist another one with the same name; it's just an example and you can change the command as you wish.
Jan 14, 2014 at 16:50