Bash if not empty - I have problem checking if string is empty.

 
I often need to detect any white space, e. . Bash if not empty

You can check if a Bash variable is empty by using an if statement and the '-z' option, if [ [ -z "$var" ]];. no content other then. Aug 27, 2012 · you can use: if read -n1 -d '' < < (command_here); then echo "Command outputs something" else echo "Command doesn't output anything" fi. 13 Answers Sorted by: 445 Previously, the question asked how to check whether there are files in a directory. If i perform ls -lrt , it shows total 0. txt ]; do echo "file is empty - keep checking it " sleep 1 # throttle the check done echo "file is not empty " cat diff. 255 123. 3 Answers. The stat command in Bash is a very useful tool that provides a lot of information about files and directories such as file permissions, size, timestamps, system information etc. printf "%s\n" "$ {mydata [@]}" | grep "^$ {val}$". 6 Methods to Check if Array Contains an Element in Bash. If you don't give whitespace after your elif, the system interprets elif[as a a particular command which is definitely not what you'd want at this time. For example, when you say "a variable that might be either null or an array of strings", people are going to assume you mean an actual array variable in the language in question, a Bash array. This script used many variables and in some cases some of the variables are referenced but empty or unset. Aug 1, 2020 · @JonathanViana Bash doesn’t have lambdas, so you’re working against the language by trying to pass a loop around. The -r option remove directories and their contents recursively including all files. Method to check if a file is empty in Bash There are several different ways to check if a file is empty in Bash, depending on your specific needs and the tools that are available on your system. A file redirection in bash will always create the file, even if the file is given no data and will thus be empty. newfile may or may not be empty--you are appending to a possibly non-empty file to begin with--but grep will have a non-zero exit status if it doesn't add anything to the file. You can see from the image that the file boolean. – deltaray. But the difference is: [ -e FILE ] True if FILE exists. Assuming there are three variables (x, y & z) whose values keep changing over a period of time and are fetched from some unique files, if any of those variables value changes to zero, then we replace that variable with. The if elif else statement in bash scripts allows creating conditional cases and responses to specific code results. If it has any value then condition is TRUE, if not then it is FALSE. Scripting also. Use rm Command. bash unix file-handling is-empty Share Improve this question Follow edited Jun 15, 2021 at 9:38 Niklas Rosencrantz 25. Bash script:. " The variable is empty. Bash で -n オプションを使って変数が空かどうかをチェックする. If you are using a different shell, just search for <my shell> operators and you will find everything you need. My problem was that the file I was trying to grep was a binary file. The British military—the leading U. txt - this file is empty. Bash provides several ways to check if a variable is set or not in Bash including the options -v, -z, -n, and parameter expansion, etc. Since the two strings are indeed not equal, the. The if elif else statement in bash scripts allows creating conditional cases and responses to specific code results. You can also get the index of an entry with grep -n, which returns the line number of a match (remember to subtract 1 to get zero-based index) This will be reasonably quick except for very large arrays. You can also get the index of an entry with grep -n, which returns the line number of a match (remember to subtract 1 to get zero-based index) This will be reasonably quick except for very large arrays. – thom. I have problem checking if string is empty. This is generally not a problem here because the script has been designed like this from the beginning. I mean to ask how to capture that 0 value. – deltaray Apr 21, 2020 at 15:40. Recursively: find /directory -type f -name '*. Detecting that you have an argument is done through the test -n $1 which is checking if a first argument exists. Here, we’ll concentrate on directories: $ find. Remove files in directory and ignore if empty-BASH. " It is part of a backup script. txt"; then echo "example. Improve this answer. I suspect you possibly could put your command into a one liner and load it into a crobtab?. Sorted by: 631. Check If a String is Not. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. The cmp command sets status code 0 if both files exist and are identical. In most UNIX implementations, the -size expression can also be used to search for file sizes of exactly N bytes ( -size Nc ), greater-than N bytes ( -size +Nc ), and less-than N bytes ( -size -Nc ). For instance, here’s a basic example: rm -r directory. There's nothing stopping COMMAND from similarly being meaningful to, and already used by, a POSIX-compliant shell interpreter. Besides, you can also use ‘for loop’ to. If the length of the string in the variable is not zero, the test returns true, and it prints that. / -maxdepth 0 -empty)" ; then echo "No new file" exit 1 fi. To check if there were no arguments provided to the command, check value of $# variable then, if [ "$*" == "" ]; then >&2 echo "No arguments provided" exit 1 fi. Check If a String is Not. Linux text match beep. The British military—the leading U. @JoshuaGoldberg bash's if operates differently than C. Of course the null and false cases cannot be converted in bash, so they are omitted. You need to pass the -z or -n option to the test command or to the if command or use conditional expression. printf "%s " "$ {mydata [@]}" | grep "^$ {val}$". Explanation: -s file1 evaluates to true if file1 exists and is not empty. And in this tutorial, I will show you 4 ways to check how to check if the variable is empty in bash:. A variable is declared and assigned with an empty string. See examples of the check and a handy freeware for managing Linux. no content other then. Let's run our script. Note that if the standard input is not empty, it is passed through ifne to the given command. Again, you can set any value: a string, integer, or float value. sh 1 $. file is a socket-t. sh 1 $. Learn how to use the test command and the if command to check if a bash variable is empty or not. Code :. @searchstar, that's only true if it's '"null"'. The test and [ commands determine their behavior based on the number of arguments; see the descriptions of those commands for any other command-specific. In our if statement we have used the -n string test operator followed by the string StdName. Note the 2>&1 operator redirecting stderr to stdout so any output on either file descriptor will be considered a failure. In an if statement, a zero exit code is mapped to "true" and a non-zero exit code is mapped to false. my script needs a parameter for output variable. , :-), bash tests for a parameter that is unset or null. sed '/^$/d' input. : command not found. Using the -empty Option. If they don't exist or are empty then also create file with cat some text. This will give you what you are looking for. However if the directory is empty or there are no csv files I get the following error:. – dbenham. To test for an empty variable you use the "if not defined" syntax (commands explicitly for variables do not require any percent signs), for example: set myvar1=foo if not defined myvar1 echo You won't see this because %myvar1% is defined. $ {parameter:-word} If parameter is unset or null, the expansion of word is substituted. You can even write them directly on the Bash command line, without using a script: if [ "1" == "1" ]; then echo 'true'; fi. " echo "The variable is not empty. Modified 4 years, 9 months ago. Improve this answer. The symbol "[" is a command and must have a whitespace prior to it. the command which you call the script and 2. You can check if a Bash variable is empty by using an if statement and the '-z' option, if [ [ -z "$var" ]];. echo "The variable is empty. To check if there were no arguments provided to the command, check value of $# variable then, if [ "$*" == "" ]; then >&2 echo "No arguments provided" exit 1 fi. zip ; do echo current file is $ {fname} done. The -v option in the ‘ if ’ statement checks whether a variable is set or assigned. Of course the null and false cases cannot be converted in bash, so they are omitted. Q&A for work. Check if folder /data/ is empty or not using bash only features. This seem not really required here, because there is no glob character in array[i], anyway. Mar 12, 2009 · Add a comment. answered Apr 24, 2018 at 15:44. Of course the null and false cases cannot be converted in bash, so they are omitted. My solution is: grep -cve '^\s*$' <file> This searches for lines in <file> the do not match (-v) lines that match the pattern (-e) '^\s*$', which is the beginning of a line, followed by 0 or more whitespace characters, followed by the end of a line (ie. -s FILE:- FILE exists and has a size greater than zero. The test && then 1 || or 2 is a standard way to condense a conditional statement of the. Detecting that you have an argument is done through the test -n $1 which is checking if a first argument exists. in files passed as input and compares its output with *. Improve this answer. Again, you can set any value: a string, integer, or float value. Returns true if the files exists and isn't empty. newfile may or may not be empty--you are appending to a possibly non-empty file to begin with--but grep will have a non-zero exit status if it doesn't add anything to the file. If not quoted, it is a pattern match! (From the Bash man page: "Any part of the pattern may be quoted to force it to be matched as a string. sh script as a regular user. Simply placing : into the section between then and else will fix. echo "File is not empty". If you also want to reject the case where BATCHNUM is empty, use $ {BATCHNUM:+a} instead of $ {BATCHNUM+a}. In our if statement we have used the -n string test operator followed by the string StdName. I tried a few solutions, but whenever I get one condition right it makes another fail, or fail when no files exist. , but not plain POSIX shells like dash ). Since in this script, k="Geek", the variable k is. Following is an example demonstrating this: if [ [ -z "$ {MY_VAR}" ]]; then echo "Empty variable, do. Scripting also. Follow the steps below to check if a file or directory exists: 1. From the question's title, this appears to be the distinction you are trying to make, but it is unclear from the question if indeed you care (or are even aware of) this distinction. The if statement employs the != operator to determine whether sone is not equal to stwo. Jun 24, 2020 · Also, in Bash, foo=$'\0' is the same as foo=, it sets foo to the empty string (the "null string"). Since the two strings are indeed not equal, the. You can use all the if else statements in a single line like this: if [ $ (whoami) = 'root' ]; then echo "root"; else echo "not root"; fi. The -n option checks if the length of the value in the string variable is nonzero. Zsh can, and there foo=$'\0'; foo=${foo:="I must have been unset!"} does not use the default value, since := only checks if the variable is unset or empty! And yeah, "I must have been unset" is wrong in. Bash provides several ways to check if a variable is set or not in Bash including the options -v, -z, -n, and parameter expansion, etc. A script is usually saved as a file and executed. file Command: The file command determines a file's type using its content. In case you need to distinguish if a variable is undefined or just has an empty value, use $ (origin VARNAME) function: ifeq ($ (origin VARNAME),undefined) VARNAME := "now it's finally defined" endif. Check to see if a variable is empty or not. function empty { local var="$1" # Return true if: # 1. Here in Bash, the two statements yielding "yes" are pattern matching, other three are string equality:. Some could also suggest that if you're just comparing numbers, use an arithmetic operator instead, or just use ( ( )): if ! [ [ var -eq 2 || var -eq 30 || var -eq 50 ]] ; then do something fi if ! ( ( var == 2 || var == 30 || var == 50 )) ; then do. There is a difference between a variable being empty and a variable being unset. Also, in Bash, foo=$'\0' is the same as foo=, it sets foo to the empty string (the "null string"). (It has the result 0 for true, which we do not. Bash variables don't have types, so there's no such thing as a boolean variable or value like true or false. If i perform ls -lrt , it shows total 0. I want to obtain the following behaviour in bash and I have the impression that this is possible in one line but I don't know the exact syntax (and was not able to find it in the doc). Now we'll edit the file and use an age less than 21. If not, I write "NXDOMAIN" to the same file. Sorted by: 1. See syntax, examples, and alternatives for different operating systems and scenarios. f # directories X and. Syntax는 다음과 같습니다. If this is your case, see the techniques described in below section Is a directory empty?. Differences: The file command goes beyond basic file checks by examining file contents, but it's not suitable for checking attributes like existence or permissions. The test is not "are any of the files not there", the test is "are none of the files there". Bash check if command returns output, and print it. As noted by @cheapner in the comments, you are not defining your arrays correctly. You are already checking status, so you should have just if grep -q – Jan Hudec. For instance: $ man bash $ man 1 test $ help [$ help [. Now, if someone put the string "null" inside a JSON. Mar 4, 2020 · Check for non-empty string in the shell (instead of ! -z) can someone just provide a good answer that will show up in search engines, hopefully if I edit the title to be optimal it will help too. The if statement employs the != operator to determine whether sone is not equal to stwo. If it did not then you can do man bash | less -r "+/\ [\ [", then press. On windows, the first two characters in the file were little squares. This option is a GNU extension. sh", and use the chmod command to make it executable. The test command takes an expression and succeeds if the expression is true; a non-empty string is an expression that evaluates as true, just as in most other programming languages. The following code achieves that, but see rsp's. With FIND (1) (under Linux and FreeBSD) you can look non-recursively at a directory entry via "-maxdepth 0" and test if it is empty with "-empty". For details about those weird cases, see my answer below. The -n flag checks if the string length is non-zero. How to check whether a directory is empty or not in Shell Scripting? 5. Same with $ {var:?error}, it'd also trigger for a set but empty value, not just an unset one. My use case exemple:. $ {PATH:+:} evaluates to nothing if PATH is not set, otherwise it evaluates to ":" This syntax is known as Shell Parameter Expansion and full documentation on this feature can be found in the man page. Sorted by: 1. My use case exemple:. PID 1 is not guaranteed to exist there: kill -0 1 -bash: kill: (1) - No such process DISCUSSION. It is a part of the package moreutils in most distros. If BAR has a value the final result should be somename-123. " fi. Or you can check if an argument is an empty string or not like: if [ -z "$1" ] then echo "No argument supplied" fi. Since in this script, k="Geek", the variable k is. This is a standard exercise in all books/blogs/manuals about shells: in bash. Would the following be sufficient to test if a variable is set AND not empty?. This then prints the number of elements in the arrays, which is 0 and 2 respectively: echo "$ {#key [@]}" echo "$ {#key1 [@]}" And this prints empty and not empty respectively:. This option is a GNU extension. My bash script: if. Checking If Variable Is Empty in Bash. The outcome is true, as 1 matches 1. The script above stores the first command-line argument in a variable and then tests the argument in the next statement. An exit status of 0 implies that it completed. var is a null string ("" as empty string) # 2. However, the output would be “First argument is empty. grep returns a different exit code if it found something (zero) vs. To check if variables are unset or empty use : before + /? character. Note: this is assuming you are already on the same level of the folder you want to delete in terminal, if not: sudo rm -r /path/to/folderName. You can't simply try to write C code and expect it to work. Single-Parentheses Syntax. The qualifier (F) lists objects that match: is a directory AND is not empty. man test has the following to say: -b FILE FILE exists and is block special -c FILE FILE exists and is character special -d FILE FILE exists and is a directory -e FILE FILE exists -f FILE FILE exists and is a regular file. Checking for variable to be non-empty in bash Hot Network Questions Do civilian aircraft transiting through controlled airspace designated for military airports typically talk to the tower of that airport?. Bash does not have a standard test for a directory being empty, like [ -f file ], so we have to write it. -z string is null, that is, has zero length To illustrate:. – Jonathan Leffler. -n オプションは、文字列変数の値の長さがゼロ以外であるかどうかを. The simple approach is to pass all directories to rmdir. I can check if variable is empty: var=("") if [[ -z "${var}" ]]; then echo "variable is empty" else echo "variable is not empty" fi Output: variable is empty But when I try to apply it to an element in an array, I get no output:. In this case I would only want to see Server One and Three as Server. Bash does not have a standard test for a directory being empty, like [ -f file ], so we have to write it. I mean to ask. This will invalidate the answer somewhat. I want to iterate through all the files of a particular type in a directory, so I write this: #!/bin/bash for fname in *. then the follwing syntax will not print - File has no content [[ $(tr -d "\r\n" < file. For example: $ mkdir /tmp/demo $ find /tmp/demo -maxdepth 0 -empty -exec echo {} is. 9k 75 231 428 asked Apr 1, 2012 at 13:41 Mich 3,363 2 14 6 47 [ -s FILE ] True if FILE exists and has a size greater than zero. Enter one of the snippets from below and make sure to include the #!/bin/bash shebang. The if keyword introduces a condition to be evaluated by a process 1. I can check if variable is empty: var=("") if [[ -z "${var}" ]]; then echo "variable is empty" else echo "variable is not empty" fi Output: variable is empty But when I try to apply it to an element in an array, I get no output:. txt"; then echo "example. 以下のスクリプトは、-n オプションを指定した test コマンドを使用して、文字列変数が空かどうかを確認します。-n オプションは、文字列変数の値の長さがゼロ以外であるかどうかをチェックします。. git/config in the web tree pointing to the new remote repo. If you had run your code you would have realized that no, -s considers that files with spaces, tabs and/or new lines are not empty. The * pattern does not match hidden names ("files with a leading dot") by default. Here are some string comparison examples using the test command. If the OP's data structure is really immutible, and intended to be exactly what it is in the question, then this is certainly correct. You can use something called Bash parameter expansion to accomplish this. In Bash, the -z and -n options are used to do the length validation tests of variables. I think that the HFS+ filesystem does not allow the deletion of files in use. How do I specify an If condition to perform something, only if the directory is empty. It would be better to set -- * (possibly setting nullglob and/or dotglob in bash first). Sorted by: 1. arabanal porn, jappanese massage porn

The outcome is true, as 1 matches 1. . Bash if not empty

Follow edited Apr 24, 2018 at 16:00. . Bash if not empty porn gay brothers

Use the -z Option. To test for an empty variable you use the "if not defined" syntax (commands explicitly for variables do not require any percent signs), for example: set myvar1=foo if not defined myvar1 echo You won't see this because %myvar1% is defined. echo "File is not empty". I suggest that you read the following resources for more info or see GNU/bash man page here: Bash Shell: Find Out If a Variable Is Set or Not; Hello World Bash Shell Script; Read documentation installed on your macOS, Unix or Linux dev box using the man command or help command. Returns true if the files exists and isn't empty. Asking for help, clarification, or responding to other answers. One of the simplest ways to check if a string is empty or null is to use the -z and -n operators. $ unset a $ b= $ c= $ [[ -v a ]] && echo "a is set" $ [[ -v b ]] && echo "b is set" b is set $ [[ -v c ]] && echo "c is set" c is set. 10 A command does not return a string (it returns a small integer exit code, usually 0 for success and 1 or 2 on failure), but it may output some data, to put in a string. Here's a simple example: var="" if [ [ -z "$var" ]]; then echo "Variable is empty" fi # Output: # Variable is empty. May 2, 2023 · Copy the script from above into an editor, save it as a file called "if-age. Though be careful if your shell script runs with the set -u option and your. Method to check if a file is empty in Bash There are several different ways to check if a file is empty in Bash, depending on your specific needs and the tools that are available on your system. " fi. From the question's title, this appears to be the distinction you are trying to make, but it is unclear from the question if indeed you care (or are even aware of) this distinction. ADVERTISEMENT Using the `test` command or ` [`. Elaborating further on BASH (since OP asked about this in BASH), the example above will not catch tabs, though it is possible to do so. The -empty test if given file is empty and is either a regular file or a directory. This will invalidate the answer somewhat. bash unix file-handling is-empty Share Improve this question Follow edited Jun 15, 2021 at 9:38 Niklas Rosencrantz 25. This technique allows for a variable to be assigned a value if another variable is either empty or is undefined. That is, a string containing only spaces should not be true under -z, because it has a non-zero length. This option is a GNU extension. It would be better to set -- * (possibly setting nullglob and/or dotglob in bash first). The script above stores the first command-line argument in a variable and then tests the argument in the next statement. 5 Ways to Check If a Variable is Empty or Not in Bash 1. All you need is: if prlctl list --info ubuntu-vm | grep -q "State: running"; then echo 'machine is running' else echo 'machine is not running' fi. Print only if field is not empty. The script above stores the first command-line argument in a variable and then tests the argument in the next statement. You learned various method. However, the output would be “First argument is empty. Note the usage of -q as an argument to grep. txt ]]; then mkdir -p /Scripts touch /Scripts/file. This technique allows for a variable to be assigned a value if another variable is either empty or is undefined. f # directories X and. Aug 30, 2010 · 12. The test && then 1 || or 2 is a standard way to condense a conditional statement of the. The first and most common method to determine if a variable is empty is by checking its length. txt fi [command2] This is checking if /Scripts/file. if find "${DIR}" -prune ! -empty -exit 1; then echo Empty else echo Not Empty fi EDIT: I think that this solution works fine with gnu find, after a quick look at the implementation. Detailed Examples & FAQ. 7 Answers Sorted by: 86 Since read reads whitespace-delimited fields by default, a line containing only whitespace should result in the empty string being assigned to the. Go to the intended location of the repository and run: git clone --bare /path/to/web/repo. ksh, dash are used a lot but are not fully bash compatible. The basic syntax is as follows: find / dir / name -empty -type -f -exec command {} \; find / dir / name -empty -type -d -exec command {} \; # GNU/BSD find command syntax: # find / path / to /dir -maxdepth 0 -empty -exec echo {} is empty. Check If a String Contains Substring, Number & Letter in Bash; Check If a String is Empty or Not in Bash [5 Methods] How to Compare Strings in Bash With if Statement [6 Methods] How to Compare Numbers in Bash With If Statement [2 Methods] Check If Array Contains an Element in Bash [6 Methods] Bash if-else Condition in One-Line [2 Ways]. This works: string=$(echo -e "\t"); if [ -z ${string// } ]; then echo "It's empty!"; fi But these. With $ {var:+x}, you get x only if the variable is set and non-empty. For information about the $ {VARIABLE+TEXT_IF_NULL} parameter expansion construct. I came looking for the general "how do you test for a PID existence in bash". On mac, the first two characters were question marks. ifne runs a given command if and only if the standard input is not empty. If Statement With Blank Variable. " fi You can use the -n test operator to test if a variable is not empty. Put the grep in an if statement. 1 Yes there is a similar thread here: Test if a variable is set in bash when using "set -o nounset" However there are so many different answers that it's not particularly clear. I've written a dummy completion script to illustrate this, with the debugging options on:. 2+, matching will by default NOT work, because the regular expression must be UNquoted in order to work and (b) the regular expression itself doesn't handle the case where the input string is a single, non-space. Q&A for work. Bash does not have a standard test for a directory being empty, like [ -f file ], so we have to write it. Also, we should note that we've to use the name of the variable in the conditional and not the value in it. You should not see any output from the find command. Add sudo at the beginning of the command : sudo rm -rf folderName. if ! grep -q sysa /etc/passwd ; then. This variation would be able to take a filename containing a newline as we don't read the name as a string with read. Jan 15, 2018 · Explanation: From man test page as follows(It checks if a variable is having any value or not. Extending @shellter's recommendation: if you use LC_ALL=C cat -vet file, it'll show nonprinting unicode characters (like nonbreaking spaces) as well as ASCII control characters. Since the command is successful, regardless of the output, you'll have to save it in a variable and pass it to your script if it isn't empty. Ask Question Asked 10 years ago. If the condition is false, it echoes ‘Variable is empty’. Improve this answer. When you absolutely require that a shell-builtin test implementation be used and are targeting a ksh-family shell such as bash, [[is the better choice: Even though modern shells do generally have built-in [implementations, that's generally a performance enhancement and the only. # The value of VARIABLE remains untouched. This answer is almost similar to Lionel’s but explore a more minimalist take by omitting the -z. Bash provides. For example: $ if true; then :; else echo; fi. [ -v N ] See a very basic example: test -v 1 && echo "1st parameter is set: '$1'" [ -v 2 ] && echo "2nd parameter is set: '$2'". If this is your case, see the techniques described in below section Is a directory empty?. txt"; then echo "example. -L returns true if the "file" exists and is a symbolic link (the linked file may or may not exist). if [[ -n "${str// /}" ]]; then echo "It is not empty!" fi "-n" means non-zero length string. To actually set the value of the variable, rather than just expanding to a default if it has no value, you can use this idiom:: ${MY_VAR:=default} which is equivalent to your original if statement. 40k 7 7 gold badges 72 72 silver badges 77 77 bronze badges. The following simple script illustrates a fairly simple way of checking if a directory is empty. Dec 30, 2022 · echo "File is empty". in file name to the list of failed tests. I would do a. The answers discussing kill and race conditions are exactly right if the body of the test is a "kill". If you think about it, that is the same behaviour as C, where '0' (a const char) will give true but 0 (an int) will give false. NOT( A AND B AND C) is the same as (NOT A) AND (NOT B) AND (NOT C); see the original question. There is a difference between a variable being empty and a variable being unset. With $ {var:+x}, you get x only if the variable is set and non-empty. If so, then the value of LC_CODE is a single carriage return, not an empty string. Start by creating a work file: mkdir scripts cd scripts. In the documentation of test you will also see a the switch -e. This will return true for /etc/hosts and false. Find out how to compare with the empty string, the null string, and the length of the variable. Then the first two slashes mean match all of the following, in our case space(s). if find "${DIR}" -prune ! -empty -exit 1; then echo Empty else echo Not Empty fi EDIT: I think that this solution works fine with gnu find, after a quick look at the implementation. In most UNIX implementations, the -size expression can also be used to search for file sizes of exactly N bytes ( -size Nc ), greater-than N bytes ( -size +Nc ), and less-than N bytes ( -size -Nc ). We use the rm command to delete a directory that is not empty. You can now use that in e. You can see from the image that the file boolean. read more here (with official reference) - Sang Nov 17, 2019 at 7:42. Returns true if the files exists and isn't empty. Ask Question Asked 10 years ago. This a simple statement to check if a file exists, is not empty and contains 0: if [[ ! -s. Find out how to compare with the empty string, the null string, and the length of the variable. Explanation: -s file1 evaluates to true if file1 exists and is not empty. Otherwise you have to quote your variables. In this case I would only want to see Server One and. if find "${DIR}" -prune ! -empty -exit 1; then echo Empty else echo Not Empty fi EDIT: I think that this solution works fine with gnu find, after a quick look at the implementation. However, I have started to use shellcheck which complains about missing quotes. echo "File is empty". Simply placing : into the section between then and else will fix. Gives False. You can see from the image that the file boolean. then the follwing syntax will not print - File has no content [[ $(tr -d "\r\n" < file. . watchhentai online