Hi, Testing a directory to be empty in bash is hackish, see http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19 The cleanest way probably is if [ -z "$(ls -A "$dir")" ]; then fi Maybe we should add a small utility which does test this in a sane way. if dirempty "$dir"; then fi
Hi, A minute ago I didn't need "dirempty", but "exists 'foo/*.bar'" test -e "foo" works fine if you have the filename. If you have wildcards it gets a bit more complicated. IMHO it would be good to have a convenience command for this instead of using some shell magic with test and ls. best regards, Erich Schubert
I think that by generalising beyond dirempty to include exists, you're getting closer to a generic unix tool. I worry though that the tool might be test(1). These seem like fairly good candidates to add to test, especially dirempty.
Erich Schubert wrote: Hmm, and dirempty is just ! exists foo/* && ! exists foo/.* , right?
Hi Joey, Maybe "exists -d foo" would be nicer for this. In many applications, "exists 'foo/*'" would do the job okay enough (if you don't plan to rm the directory) best regards, Erich Schubert
Hi, Definitely test should have had this functionality. However people will expect test to behave the same on all systems, so I'm not sure adding some non-POSIX extensions to test is a good idea. People will write scripts and use test, and then it won't work on other systems. If it's another utility, then it will be much more obvious that the tool might not exist on other systems. Furthermore some shells (busybox?) might be using a built-in test, and that wouldn't have this functionality then. best regards, Erich Schubert
Hi, +1 for the inclusion of a dirempty command into moreutils. Regards, Ax "The BTS is a voting system" el
Hi, cause there didn't happen something to this topic for some years i just made a beginning. :) Greetings, Michael
I think you can achieve this with a bash function:
exists() (
shopt -s nullglob dotglob; shopt -u failglob
a=($1); [[ ${a##*/} != . && ${a##*/} != .. && -e $a ]] && return
)
you'll use it with literal globs (like you do with "find -name" for
instance) eg:
if exists 'mydir/*'; then
echo "mydir is not empty"
else
echo "mydir is empty"
fi
also notice the faq cited earlier has moved:
http://mywiki.wooledge.org/BashFAQ/004
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19 libraries Extraction
V_/_
V_/_
http://wooledge.org/mywiki/BashFaq#head-6ec77504553115e8518271d0d319e27148634f19 libraries Extraction
I consider re-posting of out-dated URLs is spam. Joey (upstream author) made his point already years ago, I think it's time to close this bug.
Google Md Jafor Md Jafor আমি আপনার সাথে একটি পার্কিং লোকেশন শেয়ার করেছি Google Maps-এ দেখুন Google © 2018 Google LLC 1600 Amphitheatre Parkway, Mountain View, CA 94043 Md Jafor Google Maps-এর মাধ্যমে পাঠিয়েছেন
Google Md Jafor Md Jafor আমি আপনার সাথে একটি পার্কিং লোকেশন শেয়ার করেছি Google Maps-এ দেখুন Google © 2018 Google LLC 1600 Amphitheatre Parkway, Mountain View, CA 94043 Md Jafor Google Maps-এর মাধ্যমে পাঠিয়েছেন
Md Jafor's locationShared with you on Google Mapshttps://maps.app.goo.gl?link=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2&apn=com.google.android.apps.maps&amv=949000000&ius=comgooglemapsurl&isi=585027354&ct=location-sharing-fdl&mt=8&pt=9008&ibi=com.google.Azimuth&ibi=com.google.Azimuth.MessagesExtension&ibi=com.google.Bzimuth&ibi=com.google.Bzimuth.MessagesExtension&ibi=com.google.Czimuth&ibi=com.google.Czimuth.MessagesExtension&ibi=com.google.Dzimuth&ibi=com.google.Dzimuth.MessagesExtension&ibi=com.google.Maps&ibi=com.google.Maps.MessagesExtension&ibi=com.google.Rzimuth&ibi=com.google.Rzimuth.MessagesExtension&afl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2&ifl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZxNXVnSG1yc3BqUVRDNWI5dlNyekZR!2e2Learn more at https://support.google.com/maps/?p=share_location_desktopGoogle Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
Md Jafor's locationShared with you on Google Mapshttps://maps.app.goo.gl?link=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2&apn=com.google.android.apps.maps&amv=949000000&ius=comgooglemapsurl&isi=585027354&ct=location-sharing-fdl&mt=8&pt=9008&ibi=com.google.Azimuth&ibi=com.google.Azimuth.MessagesExtension&ibi=com.google.Bzimuth&ibi=com.google.Bzimuth.MessagesExtension&ibi=com.google.Czimuth&ibi=com.google.Czimuth.MessagesExtension&ibi=com.google.Dzimuth&ibi=com.google.Dzimuth.MessagesExtension&ibi=com.google.Maps&ibi=com.google.Maps.MessagesExtension&ibi=com.google.Rzimuth&ibi=com.google.Rzimuth.MessagesExtension&afl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2&ifl=https://www.google.com/maps/@/data%3D!4m5!7m4!1m2!1s111324023244013987696!2sChZlZGczRFVwb3FBMDYwSmpDYlpmWGxREggHBgGx7ZqBbQ%253D%253D!2e2Learn more at https://support.google.com/maps/?p=share_location_desktopGoogle Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043