- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh: check if a shell variable contains spaces or ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 07:44 AM
06-18-2014 07:44 AM
ksh: check if a shell variable contains spaces or is empty (maybe with case regexp)
hello,
i have to check, if a shell variable contains only space(s) or is empty.
i tried to change the "case" regexp of this example :
Testing a string containing only spaces (tabs, or “ ”)?
case $string in (*[^[:blank:]]*) echo "string is not blank";; ("") echo "string is empty";; (*) echo "string is blank" esac
so i made tests with "grep" and the "regexp"
string="" # Return-Code: 0 echo "${string}" | grep "^[[:space:]]*[[:space:]]*$" echo $? string=" " # Return-Code: 0 echo "${string}" | grep "^[[:space:]]*[[:space:]]*$" echo $? string=" test " # Return-Code: 1 echo "${string}" | grep "^[[:space:]]*[[:space:]]*$" echo $?
here is my version, but it doesn't work, also i don't know the syntax (... til)
case "${string}" in (^[[:space:]]*[[:space:]]*$) echo "string contains space(s)" ;; ("") echo "string is empty" ;; (*) echo "string is not blank" ;; esac
regards
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2014 12:23 AM
06-19-2014 12:23 AM
Re: ksh: check if a shell variable contains spaces or is empty (maybe with case regexp)
case and [[ = ]] do pattern matching, not regex.
So you would need to do sed, grep or awk.
I suppose you could use "typeset -L" to strip leading spaces and if the result matches " *", (space star), you have what you wanted.