码迷,mamicode.com
首页 > 系统相关 > 详细

Shell basic1

时间:2015-02-14 12:16:24      阅读:208      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!