[ start | index | login ]

bash

Created by kron. Last edited by retep, 2 years and 356 days ago. Viewed 9,081 times. #4
[diff] [history] [edit] [rdf]
labels
attachments
Bash Cheat Sheet

-d check if the file is a directory
-e check if the file exists
-f check if the file is a regular file
-g check if the file has SGID permissions
-r check if the file is readable
-s check if the file's size is not 0
-u check if the file has SUID permissions
-w check if the file is writeable
-x check if the file is executable

Checks equality between numbers:
x -eq y Check is x is equals to y
x -ne y Check if x is not equals to y
x -gt y Check ifx is greater than y
x -lt y Check if x is less than y

Checks equality between strings:
x = y Check if x is the same as y
x != y Check if x is not the same as y
-n x Evaluates to true if x is not null
-z x Evaluates to true if x is null

Trapping CTRL-C in a Bash Script

#!/bin/bash

# trap ctrl-c and call ctrl_c() trap ctrl_c INT

function ctrl_c() { echo "** Trapped CTRL-C!" }

for i in `seq 1 5`; do sleep 1 echo -n "." done

请以发表评论身份登录
Powered by snipsnap.org Found a mistake in a howto? Let us know via an email to p.blikibugs at rimuhosting com.