LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell scripting and bin folder (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-and-bin-folder-4175520298/)

jazzo 09-27-2014 10:08 AM

shell scripting and bin folder
 
Hello chaps, I'm totally new to shell scripting and I'm reading a few tutorials. Now, they say that the script should be placed inside a bin folder and that often this folder needs to be created. I'm running ubuntu 12.04 and I do have this folder already and it's full of all sort of stuff from executables to whatnot. Now, one of the first things the tutorial said was to create an empty file inside the bin folder, with the following command
Code:

touch ~bin/datecp
but I got a permission denied error. So, I prefixed it with the sudo command and everything went OK. So I wonder, is this normal? Do I have to prefix every command I run for the bin folder with sudo - seems a bit odd - or did I get things wrong and in fact I do need to create another bin folder elsewhere?
thanks

273 09-27-2014 10:13 AM

I think you ought to look for a different tutorial. Creating scripts in /bin as you lern ks a stupid idea which could cause problems if you mess up.

dijetlo 09-27-2014 10:59 AM

Generally tutorials tell you to put a "bin" in your users home directory and append it to your users $PATH, not test scripts in /bin which is part of the systems $PATH.
The first lets you execute your new scripts from any location in the file system.
The second is a recipe for disaster.
You're doing the second.
What I do is create a directory in which I work on scripts and go there to write and test them (at first). Once I know it executes more or less as I expected, I move it somewhere it can do some real damage (and append the somewhere to the system $PATH if I have to).
Having the $PATH variable include your scriptorium is not really neccessary (or even desirable) during development. Untested scripts tend to have unintended consequences so a little care saves a lot of time.

pan64 09-27-2014 11:32 AM

I think you missed a very important char:
that should be: ~/bin (that is a bin folder inside your home)

jazzo 09-27-2014 04:01 PM

thanks guys, I will create the new bin folder in my home directory then! One thing, I did change the permissions on the original bin folder though:
Code:

antobbo@antobbo-linux-Dell-System-XPS-L702X:/bin$ sudo chmod u+x ~bin/datecp
Is that bad or is it OK?
thanks

suicidaleggroll 09-27-2014 06:43 PM

You're missing a critical "/" there. It should be ~/bin, not ~bin. And no, "chmod u+x ~bin" won't cause any problems.

jazzo 09-28-2014 01:19 PM

thanks, no I'm not missing the /, I changed the permission of the default bin folder

pan64 09-28-2014 02:53 PM

so just check that tutorial again, that should be ~/bin. changing the permission of that bin folder is not recommended at all.

Habitual 09-28-2014 04:22 PM

BIG difference between
Code:

echo ~bin
/bin

and
Code:

echo ~/bin
/home/jj/bin

Executing code incorrectly on one of those can ruin you whole day.


All times are GMT -5. The time now is 09:24 PM.