{"action":"created","issue":{"url":"https://api.github.com/repos/imposters-handbook/feedback/issues/62","repository_url":"https://api.github.com/repos/imposters-handbook/feedback","labels_url":"https://api.github.com/repos/imposters-handbook/feedback/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/imposters-handbook/feedback/issues/62/comments","events_url":"https://api.github.com/repos/imposters-handbook/feedback/issues/62/events","html_url":"https://github.com/imposters-handbook/feedback/issues/62","id":172719492,"number":62,"title":"Mention executable shell scripts","user":{"login":"jmurty","id":65604,"avatar_url":"https://avatars.githubusercontent.com/u/65604?v=3","gravatar_id":"","url":"https://api.github.com/users/jmurty","html_url":"https://github.com/jmurty","followers_url":"https://api.github.com/users/jmurty/followers","following_url":"https://api.github.com/users/jmurty/following{/other_user}","gists_url":"https://api.github.com/users/jmurty/gists{/gist_id}","starred_url":"https://api.github.com/users/jmurty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmurty/subscriptions","organizations_url":"https://api.github.com/users/jmurty/orgs","repos_url":"https://api.github.com/users/jmurty/repos","events_url":"https://api.github.com/users/jmurty/events{/privacy}","received_events_url":"https://api.github.com/users/jmurty/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/imposters-handbook/feedback/labels/bug","name":"bug","color":"ee0701"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-23T14:47:52Z","updated_at":"2016-09-17T16:20:13Z","closed_at":null,"body":"The shell script examples at the start of the book tend to use functions heavily, which for me is an unusual practice.\r\n\r\nWrapping shell script behaviour in functions can be useful because the functions can be loaded into the shell and will always be readily available.\r\n\r\nHowever I think it would be worthwhile to mention the more common (?) approach of starting shell scripts with a hash-bang and making them executable. You need to type the path to the file for these scripts, but they are easier to share because they can live in the code repositories to which they apply and there's no risk of function name clashes. You still have access to all the `$1` variables with this approach, though you claim otherwise in \"Start with a Function\" where you say functions are necessary to use variables.\r\n\r\nAs an example, the \"new_post\" script could also be written to a _new_post.sh_ file with:\r\n* `#!/bin/bash` on the first line, to explicitly specify it as a bash script (or zsh if you want)\r\n* make it executable with `chmod u+x new_posts.sh`, so you can invoke `new_posts.sh` to run it instead of `sh new_posts.sh`\r\n* no need for the `new_post()` function wrapper around the remainder of the script.\r\n\r\nMaybe all this ceremony to make the shell scripts directly runnable is unnecessary overhead for your examples, but I think it's worth mentioning the alternate approach."},"comment":{"url":"https://api.github.com/repos/imposters-handbook/feedback/issues/comments/247785841","html_url":"https://github.com/imposters-handbook/feedback/issues/62#issuecomment-247785841","issue_url":"https://api.github.com/repos/imposters-handbook/feedback/issues/62","id":247785841,"user":{"login":"ScottESanDiego","id":6334448,"avatar_url":"https://avatars.githubusercontent.com/u/6334448?v=3","gravatar_id":"","url":"https://api.github.com/users/ScottESanDiego","html_url":"https://github.com/ScottESanDiego","followers_url":"https://api.github.com/users/ScottESanDiego/followers","following_url":"https://api.github.com/users/ScottESanDiego/following{/other_user}","gists_url":"https://api.github.com/users/ScottESanDiego/gists{/gist_id}","starred_url":"https://api.github.com/users/ScottESanDiego/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScottESanDiego/subscriptions","organizations_url":"https://api.github.com/users/ScottESanDiego/orgs","repos_url":"https://api.github.com/users/ScottESanDiego/repos","events_url":"https://api.github.com/users/ScottESanDiego/events{/privacy}","received_events_url":"https://api.github.com/users/ScottESanDiego/received_events","type":"User","site_admin":false},"created_at":"2016-09-17T16:20:13Z","updated_at":"2016-09-17T16:20:13Z","body":"Agreed - the paradigm that I use and see in the wild is exactly what the OP mentioned - shebang shell scripts and call them directly as if they are standalone programs rather than extending the shell with functions.  +1 for the recommendation."}}
{"actor":{"display_login":"ScottESanDiego"}}