7 shell while 读文件
写法1
#!/bin/bash
while read line
do
echo $line
done < file(待读取的文件)
--------------------------------------------------
写法二:
cat file(待读取的文件) | while read line
do
echo $line
done
-----------------------------------------------------
写法三:
for line in `cat file(待读取的文件)`
do
echo $line
done
-----------------------------------------------------
简写:
$ cat file | while read line; do echo $line; done
$ for line in $(<file); do echo $line; done
=== 实践 ===
#! bin/sh
#$str='http://images.stylight.de/static/res200/s2870/2870657.1.jpg%0D'
while read line
do
wget -p ${line:0:59}
done <‘XXX’;
#6 if else
if [ expression ]
then
XXX
else
XXX
fi
#5 shell写log
cat >run.sh
exec >XXX.run.log 2>&1
echo Start time:
date
#4 rename“--”
for file in $(find ./ -name "*");do mv $file $(echo "$file"|sed 's/\-\-P5//');done
#0 查看centos系统版本号
cat /etc/redhat-release
#1 读取脚本的绝对路径目录
g_progdir_abs=$(dirname "$(readlink -f "$0")");
#2 提示参数
if [ $# -lt 1 ]; then
echo "Usage: sh <ref> <bam> <sample> <output>"
exit
fi
# 3 写function
name(){
echo “${g_prog:=$0}: Error! ""$@" 1>&2;
exit 1;
}
linux中shell变量@,1,*
所有参数列表。如"1 n"的形式输出所有参数。
@"用「"」括起来的情况、以"2" … "#
添加到Shell的参数个数
# 3 判断空字符串
if [[ ! -z "${SMRT_IGNORE_CUSTOM_PIPELINES:-}" ]] ; then -z 空字符串返回为真
# 4 改~家目录环境变量
export HOME=/data/username
网友评论