{"id":22,"date":"2013-12-18T21:00:00","date_gmt":"2013-12-18T21:00:00","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/Hayek\/Jochen\/wp\/blog-en\/2013\/12\/18\/shell-code-and-useless-use-of-ls-tar\/"},"modified":"2013-12-18T21:00:00","modified_gmt":"2013-12-18T21:00:00","slug":"shell-code-and-useless-use-of-ls-tar","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2013\/12\/18\/shell-code-and-useless-use-of-ls-tar\/","title":{"rendered":"shell code and useless use of &#8220;ls *.tar&#8221;"},"content":{"rendered":"<p>\t\t\t\tConsider this code (I came across such Korn shell script code recently):<\/p>\n<blockquote><p>\n<span>TARFILE=$(ls -1 \/tmp\/*.tar)<\/span><\/p><\/blockquote>\n<p>According to\u00a0<a href=\"http:\/\/partmaps.org\/era\/unix\/award.html#ls\">http:\/\/partmaps.org\/era\/unix\/award.html#ls<\/a>\u00a0you ought to replace the ls with a glob, e.g. like this:<\/p>\n<blockquote><p>\n<span>[[ -s \/tmp\/*.tar ]] &amp;&amp; set -A tarfiles \/tmp\/*.tar<br \/>for TARFILE in &#8220;${tarfiles[@]}&#8221;<br \/>do<br \/>\u00a0 : # &#8230;<br \/>done<\/span><\/p><\/blockquote>\n<p>Instead you may want to enquire <span>${#tarfiles[@]}<\/span>, i.e. the number of files globbed.<\/p>\n<p>Please forgive me the naming here! I was happy to take this note anyway.\t\t\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consider this code (I came across such Korn shell script code recently): TARFILE=$(ls -1 \/tmp\/*.tar) According to\u00a0http:\/\/partmaps.org\/era\/unix\/award.html#ls\u00a0you ought to replace the ls with a glob, e.g. like this: [[ -s \/tmp\/*.tar ]] &amp;&amp; set -A tarfiles \/tmp\/*.tarfor TARFILE in &#8220;${tarfiles[@]}&#8221;do\u00a0 : # &#8230;done Instead you may want to enquire ${#tarfiles[@]}, i.e. the number of files [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[666],"tags":[],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-m","jetpack_likes_enabled":true,"amp_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":0,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}