bash shell 자체는 integer arithmetic 만 지원. bc 를 이용해야함


example)

LINK_UTIL=`printf "%.10f\n" $(bc -l <<< "scale=10; ${A}/${B}") `


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,

출처 : http://apple.stackexchange.com/questions/66611/how-to-change-computer-name-so-terminal-displays-it-in-mac-os-x-mountain-lion


If you use:

sudo scutil --set HostName name-you-want

it will work a bit better. From the scutil(8) man page:

--get pref
    Retrieves the specified preference.  The current value will be
    reported on standard output.

    Supported preferences include:
          ComputerName   The user-friendly name for the system.
          LocalHostName  The local (Bonjour) host name.
          HostName       The name associated with hostname(1) and gethostname(3).

--set pref [newval]
    Updates the specified preference with the new value.  If the new value is not
    specified on the command line then it will be read from standard input.

    Supported preferences include: ComputerName LocalHostName HostName

    The --set option requires super-user access.


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,

출처 : http://www.cyberciti.biz/faq/shell-how-to-determine-the-exit-status-of-linux-and-unix-command/



Shell: How to determine the exit status of Linux and UNIX command


Q. Can you explain the exit status of shell and commands under Linux / UNIX operating system?

A. All UNIX and Linux command has a several parameters or variables that can be use to find out the exit status of command. Please note that these parameters or variables may only be referenced assignment to them is not allowed. You can use $? to find out the exit status of command. $? always expands to the status of the most recently executed foreground command or pipeline. For example, you run the command cal:
$ cal
Now to see exit status of cal command type following command:
$ echo $?
Output:

0

Zero means command executed successfully, if exit status returns non-zero value then your command failed to execute. For example run command called cyberciti
$ cyberciti
Output:

bash: cyberciti: command not found

Display exit status of the command:
$ echo $?
Output:

127

Value 127 (non-zero) indicates command cyberciti failed to execute. You can use exit status in shell scripting too. You can store result of exit status in variable. Consider following shell script:

#!/bin/bash
echo -n "Enter user name : "
read USR
cut -d: -f1 /etc/passwd | grep "$USR" > /dev/null
OUT=$?
if [ $OUT -eq 0 ];then
   echo "User account found!"
else
   echo "User account does not exists in /etc/passwd file!"
fi
 

Save and execute the script as follows:
$ chmod +x script.sh
$ ./script.sh

Output:

Enter user name : jradmin
User account does not exists in /etc/passwd file

Try it one more time:
$ ./script.sh
Output:

Enter user name : vivek
User account found

As you can see, I have used grep command to find out user name stored in USR variable. If grep command finds user name in /etc/passwd command output it would return exit status of zero. This is stored in OUT variable. Next, if command makes decision based upon exit status stored in OUT variable.


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,

출처 : http://www.thelinuxdaily.com/2012/03/simple-stopwatch-script/



Simple Stopwatch Script


The following is a short and plain shell script that will start a timer when you run the program that counts up. I think you could argue that it’s not a stopwatch because it doesn’t support laps, but it’s close enough for me. You can easy get started by copying the following code block into a text editor, saving as stopwatch.sh, running chmod +x stopwatch.sh to make it executable, and finally starting it with ./stopwatch.sh. To stop it, hit Ctrl+c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
 
BEGIN=$(date +%s)
 
echo Starting Stopwatch...
 
while true; do
   NOW=$(date +%s)
   let DIFF=$(($NOW - $BEGIN))
   let MINS=$(($DIFF / 60))
   let SECS=$(($DIFF % 60))
   let HOURS=$(($DIFF / 3600))
   let DAYS=$(($DIFF / 86400))
 
   # \r  is a "carriage return" - returns cursor to start of line
   printf "\r%3d Days, %02d:%02d:%02d" $DAYS $HOURS $MINS $SECS
   sleep 0.25
done

The previous script will allow you to track from the time you say “go” until you stop it. It’s also nice to the real-estate on your terminal and will use backspace to remove the characters printed from before to make room for the new ones.

If you’re not worried about starting it “now” or real estate in the terminal, you could always use uptime and throw it into a while loop like this:

1
2
3
#!/bin/sh
 
while true; do uptime | cut -d' ' -f2; done

Both are simple, both have their own advantages and disadvantages. Choose wisely. ;-)

Source: unix.com forums

I used the scripts to help me figure out how long it was taking my desktop to lock up so I could troubleshoot it better. Another use might be to keep track of how much time you’re spending on the computer vs the amount of time spent skiing! Have fun either way.

Edit
A subscriber, Jim, came up with a much better stopwatch script than my thrown together example. Jim sent it via email, but I’ll post it here for all to see.

It doesn’t start counting till you press the spacebar, pressing the
spacebar again pauses it counting, until the spacebar is pressed to
continue counting.

Press ‘q’ to quit
Press ‘r’ to reset to zero

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
 
# sets stdin to no echo and give a char every tenth of a sec.
stty -echo -icanon time 1 <&0
 
chkspace () {
 
  if ! read -t 0 ; then return 1 ; fi    # no char pressed
  read -n 1 ans
  if [ "$ans" = " " ]; then return 0 ; fi
  case "$ans" in
  r|R)  COUNT=0 ; BEGIN=$(date +%s)
        printf "\r%3d Days, %02d:%02d:%02d" 0 0 0 0
        ;;
  q|Q)  stty echo icanon <&0
        echo ""
        exit 0
        ;;
  [1-9]) echo " - $ans" ;;
  esac
  return 1
}
 
echo "Stopwatch: to start and stop press the SPACEBAR..."
 
printf "\r%3d Days, %02d:%02d:%02d" 0 0 0 0
 
COUNT=0
IFS=
while true ; do
 
  while true; do
    if chkspace ; then break; fi
    sleep 0.1
  done
 
  BEGIN=$(date +%s)
  while true; do
    NOW=$(date +%s)
    let DIFF=$(($NOW - $BEGIN + $COUNT))
 
    let MINS=$(($DIFF / 60))
    let SECS=$(($DIFF % 60))
    let HOURS=$(($DIFF / 3600))
    let DAYS=$(($DIFF / 86400))
 
    # \r  is a "carriage return" - returns cursor to start of line
    printf "\r%3d Days, %02d:%02d:%02d" $DAYS $HOURS $MINS $SECS
 
    if chkspace ; then break; fi
    sleep 0.1
  done
 
  COUNT=$DIFF
done


WRITTEN BY
RootFriend
개인적으로... 나쁜 기억력에 도움되라고 만들게되었습니다.

,