How to check the first character in a string in Bash or UNIX shell?

前端 未结 4 411
无人共我
无人共我 2021-01-30 06:07

I\'m writing a script in UNIX where I have to check whether the first character in a string is \"/\" and if it is, branch.

For example I have a string:

/         


        
4条回答
  •  孤街浪徒
    2021-01-30 06:59

    Consider the case statement as well which is compatible with most sh-based shells:

    case $str in
    /*)
        echo 1
        ;;
    *)
        echo 0
        ;;
    esac
    

提交回复
热议问题