{"id":28,"date":"2011-07-19T12:13:30","date_gmt":"2011-07-19T12:13:30","guid":{"rendered":"http:\/\/www.vidarholen.net\/contents\/blog\/?p=28"},"modified":"2015-04-06T17:25:58","modified_gmt":"2015-04-06T17:25:58","slug":"why-bash-is-like-that-builtin-or-not","status":"publish","type":"post","link":"https:\/\/www.vidarholen.net\/contents\/blog\/?p=28","title":{"rendered":"Why Bash is like that: Builtin or not"},"content":{"rendered":"<p>Bash can seem pretty random and weird at times, but most of what people see as quirks have very logical (if not very good) explanations behind them. This series of posts looks at some of them.<\/p>\n<pre># Why don't the options in \"man time\" work?\r\ntime -f %w myapp<\/pre>\n<p><strong>Short answer: &#8216;time&#8217; runs the builtin version, &#8216;man time&#8217; shows the external version<\/strong><\/p>\n<p><code>time<\/code> is a builtin in the shell, as well as an external command (this also goes for kill, pwd, and test). The <code>man time<\/code> shows info about the external command, while <code>help time<\/code> shows the internal one.<\/p>\n<p>To run the external version, one can use <code>command time<\/code> or <code>\/usr\/bin\/time<\/code> or just <code>\\time<\/code>.<\/p>\n<p>The reason why time is built in is so timing pipelines will work properly. <code>time true | sleep 10<\/code> would say 0 seconds with an external command (which can&#8217;t know what it&#8217;s being piped into), and while the internal version can say 10 seconds since it knows about the whole pipeline.<\/p>\n<p>POSIX leaves the behaviour of <code>time a | b<\/code> undefined.<\/p>\n<pre># This finds the full path to ls. Why isn't there a 'man type'?\r\ntype -P ls<\/pre>\n<p>type is a bash builtin, not an external command. This allows it to take shell functions and aliases into account, something whereis can&#8217;t.<\/p>\n<p>Builtins are documented in man bash, or more conveniently, &#8220;help type&#8221; (help is also a builtin).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bash can seem pretty random and weird at times, but most of what people see as quirks have very logical (if not very good) explanations behind them. This series of posts looks at some of them. # Why don&#8217;t the options in &#8220;man time&#8221; work? time -f %w myapp Short answer: &#8216;time&#8217; runs the builtin &hellip; <a href=\"https:\/\/www.vidarholen.net\/contents\/blog\/?p=28\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Why Bash is like that: Builtin or not&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[6],"tags":[11,21,39],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-basic-linux","tag-bash","tag-shell-script","tag-why-bash-is-like-that"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":1,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}