shell去除换行和空格

#!/bin/bash

if [ -f str.txt ]   ## 如果str.txt存在,则返回true
then
   strval=$(cat str.txt|awk '{printf "%s",$1}'|sed 's/ //g')    ## 使用awk去除换行,使用sed去除空格
   if [ "" == "$strval" ]     ## 判断文件是否为空
   then echo "empty"
   elif [ "all" == "$strval" ]  ## 判断文件的内容是否为all
    then echo "backup all"
   else echo "backup part"
   fi
else
  echo "str.txt not exist"
fi
原文地址:https://www.cnblogs.com/qq931399960/p/5618893.html