LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-27-2014, 11:08 AM   #1
jazzo
Member
 
Registered: Jul 2012
Posts: 192

Rep: Reputation: Disabled
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
 
Old 09-27-2014, 11:13 AM   #2
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,004

Rep: Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620Reputation: 1620
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.
 
Old 09-27-2014, 11:59 AM   #3
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,307
Blog Entries: 2

Rep: Reputation: Disabled
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.

Last edited by dijetlo; 09-27-2014 at 12:04 PM. Reason: IS...IF... little difference are important...
 
1 members found this post helpful.
Old 09-27-2014, 12:32 PM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
I think you missed a very important char:
that should be: ~/bin (that is a bin folder inside your home)
 
Old 09-27-2014, 05:01 PM   #5
jazzo
Member
 
Registered: Jul 2012
Posts: 192

Original Poster
Rep: Reputation: Disabled
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
 
Old 09-27-2014, 07:43 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You're missing a critical "/" there. It should be ~/bin, not ~bin. And no, "chmod u+x ~bin" won't cause any problems.
 
Old 09-28-2014, 02:19 PM   #7
jazzo
Member
 
Registered: Jul 2012
Posts: 192

Original Poster
Rep: Reputation: Disabled
thanks, no I'm not missing the /, I changed the permission of the default bin folder
 
Old 09-28-2014, 03:53 PM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
so just check that tutorial again, that should be ~/bin. changing the permission of that bin folder is not recommended at all.
 
Old 09-28-2014, 05:22 PM   #9
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,163
Blog Entries: 10

Rep: Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979Reputation: 1979
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux dust bin shell scripting booboo84 Linux - Software 3 11-28-2012 03:32 AM
[SOLVED] Shell Scripting for Recycle Bin. Delete,Trash,Restore mohitnarula Linux - Newbie 27 11-27-2012 04:27 PM
/usr/bin/time Shell Scripting Function solo2 Programming 7 10-12-2011 05:25 AM
[SOLVED] Randomly select a folder using Shell Scripting kapz_unlocked Linux - Newbie 7 06-21-2011 01:02 AM


All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration