首页 > 系统服务 > 详细

Shell basic1

时间:2015-02-14 12:15:32      阅读:249      评论:0      收藏:0      [点我收藏+]

A shell script is a text file that typically begins with a shebang, as follows:

#!/bin/bash

/bin/bash is

the interpreter command path for Bash.

$ sh /home/path/script.sh # Using full path of script.sh.

chmod a+x script.sh

#character is used to denote the beginning of unprocessed comments.

For every

process, environment variables in its runtime can be viewed by:

cat /proc/$PID/environ

cat /proc/12501/environ

cat /proc/2849/environ | tr ‘\0‘ ‘\n‘

Then you can split the environment string to property=value format.

Judge the current user is super user or not:

if [ $UID -ne 0 ]; then

echo Non root user. Please run as root.

else

echo "Root user"

Fi

File descriptors are integers that are associated with file input and output. They keep track

of opened files. The best-known file descriptors are stdin, stdout, and stderr.

0 – stdin(standard input)

1 – stdout(standard output)

2 – stderr(standard error)

#!/bin/bash

#Description: Illustration of IFS

line="root:x:0:0:root:/root:/bin/bash" 

oldIFS=$IFS;

IFS=":"

count=0

for item in $line;

do

[ $count -eq 0 ] && user=$item;

[ $count -eq 6 ] && shell=$item;

let count++

done;

IFS=$oldIFS

echo $user\‘s shell is $shell;
  • -gt: Greater than
  • -lt: Less than
  • -ge: Greater than or equal to
  • -le: Less than or equal to

Shell basic1

原文:http://www.cnblogs.com/huaxiaoyao/p/4291392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!