Sapiens Search

Showing posts with label shell scripting. Show all posts
Showing posts with label shell scripting. Show all posts

How to prompt for a password when running a command or script?

kdesudo "<Full command>"

Example

1 - Open the run command with Alt+F2
2 - To reboot (needs root), for example, type:
kdesudo "shutdown -r now"
3- Type your root password and hit Return
4 - Your system will reboot after this

 Arcam Sapientia

You can use this on scripts to prompt for a pass when it is needed.

#!/bin/sh
clementine
kdesudo "shutdown -r 00:00"

This will open the clementine music player and reboot at 00:00 time.

How to use floating numbers in Shell Script?

<variable> =`echo "scale=<precision>;<operations>"`

Example:

Write a code file named float as follow:

#!/bin/sh
floatNumber=`echo "scale=2;1/2" | bc`
echo $floatNumber

When you run it, the result will be:
$./float
.50