最後更新: 2016-02-18
介紹
ash (Kenneth Almquist's ash shell)
A lightweight (92K) Bourne compatible shell.
Ash is also fairly popular in embedded Linux systems; its code was incorporated into the BusyBox
Config File
$HOME/.profile
/etc/profile
#!/bin/sh [ -f /etc/banner ] && cat /etc/banner export PATH=/bin:/sbin:/usr/bin:/usr/sbin export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6) export HOME=${HOME:-/root} export PS1='\u@\h:\w\$ ' [ -x /bin/more ] || alias more=less [ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi [ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc [ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } #### Add by datahunter #### export PS1='\u@\h:\W\$ ' alias u='cd ..' alias ll='ls -lsh --color=yes' alias la='ls -lah --color=yes' alias p="ping -c 3 8.8.8.8" alias rm='rm -i' alias mv='mv -i' alias cp='cp -i'
Function
#!/bin/ash myfunction(){ echo "I 'm function" } myfunction
while
Syntax
#!/bin/ash while [ true ]; do sleep 3 echo "Testing" done
break & continue
break [ num ] continue [ num ]
if
Syntax
if list; then list elif list; then list else list fi
Example
# -eq -ne
if [ $? -eq 0 ]; then ping -q -c 4 8.8.8.8 if [ $? -ne 0 ]; then /usr/local/bin/myscript fi fi
for
services='service1 service2 service3' for s in $services ; do START "$s" done
Example
# 1 - Disallow access fb, youtube
#!/bin/ash flagfile="/tmp/BlockDomain.txt" DisableTime="09 10 11 14 15 16 17 18" now=`date +"%H"` # Check Block for t in $DisableTime do if [ $now -eq $t ]; then if [ -e $flagfile ]; then echo "No need run Block" touch $flagfile # for checking exit fi echo "Run Block" echo 'address=/facebook.com/127.0.0.1' >> /etc/dnsmasq.conf echo 'address=/youtube.com/127.0.0.1' >> /etc/dnsmasq.conf killall dnsmasq dnsmasq --log-async pidof dnsmasq touch $flagfile exit fi done # Allow if [ -e $flagfile ]; then echo "Run Allow" # refresh /etc/dnsmasq.conf service restart_dnsmasq rm -f $flagfile else echo "No need run Allow" fi
DOC
http://linux.die.net/man/1/ash