Shell 脚本
最后发布时间:2022-01-24 18:19:55
浏览量:
pid=$(jps | grep "bioinfo-0.0.1-SNAPSHOT.jar" | awk '{print $1}')
判断变量
read -p "input a word :" word
if [ ! -n "$word" ] ;then
echo "you have not input a word!"
else
echo "the word you input is $word"
fi
判断输入参数
#!/bin/bash
if [ ! -n "$1" ] ;then
echo "you have not input a word!"
else
echo "the word you input is $1"
fi
直接通过变量判断
#!/bin/sh
para1=
if [ ! $para1 ]; then
echo "IS NULL"
else
echo "NOT NULL"
fi
使用test判断
#!/bin/sh
dmin=
if test -z "$dmin"
then
echo "dmin is not set!"
else
echo "dmin is set !"
fi
使用""判断
#!/bin/sh
dmin=
if [ "$dmin" = "" ]
then
echo "dmin is not set!"
else
echo "dmin is set !"
fi
pubmed下载
#!/usr/bin/env bash
Link="http://www.ncbi.nlm.nih.gov/pubmed/"
PMCLink="http://www.ncbi.nlm.nih.gov/pmc/articles/"
ID=(33719338 77777777)
for f in ${ID[@]};
do
echo "${Link}${f}"
PMCID=$(wget --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" \
-l1 --no-parent ${Link}${f} -O - 2>/dev/null | grep -Po 'PMC\d+' | head -n 1)
echo "$PMCID"
if [ $PMCID ]; then
wget --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" \
-l1 --no-parent -A.pdf ${PMCLink}${PMCID}/pdf/ -O ${f}.pdf 2>/dev/null
else
echo "No PMC ID for $f"
fi
done
#!/usr/bin/env bash
Link="http://www.ncbi.nlm.nih.gov/pubmed/"
PMCLink="http://www.ncbi.nlm.nih.gov/pmc/articles/"
# ID=(33719338 77777777)
PID=$1
if ! test $PID ;then
echo "please input PID!"
exit
fi
OUT_NAME=$PID
if test $2; then
OUT_NAME=$2
fi
echo "downlaod: ${Link}${PID} - ${OUT_NAME}"
PMCID=$(wget --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" \
-l1 --no-parent ${Link}${PID} -O - 2>/dev/null | grep -Po 'PMC\d+' | head -n 1)
echo "$PMCID"
if [ $PMCID ]; then
wget --user-agent="Mozilla/5.0 (Windows NT 5.2; rv:2.0.1) Gecko/20100101 Firefox/4.0.1" \
-l1 --no-parent -A.pdf ${PMCLink}${PMCID}/pdf/ -O ${OUT_NAME}.pdf 2>/dev/null
else
echo "No PMC ID for $PID"
fi
文件夹不存在则创建
if [ ! -d "/data/" ];then
mkdir /data
else
echo "文件夹已经存在"
fi
文件存在则删除
if [ ! -f "/data/filename" ];then
echo "文件不存在"
else
rm -f /data/filename
fi