LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2014, 03:16 PM   #1
io.centos
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
First bash script


Hi everyone

I recently started playing with shell scripting and i started with bash.
I have written a small script to backup specific files that i want( although it is not finished yet ).
So the idea is that i can add directory and file paths to a second file and when i execute the backup it will only backup these specific files and directories.


So i have my script somewhere in my home directory. But the sript make use of a helper file where the paths are stored. Where would be the best place to store this kind of files? Secondary files that are used to keep only data. I mean if i give this script to someone to use and i want this second file somewhere safe and with access to it.

Thanks
 
Old 06-04-2014, 03:33 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
I gather that this backup script only backs up one user's data and therefore does not require root permissions. So putting the support file is /etc would probably not be ideal.

One common place for per-user configs is in a user's home directory. Let's say your backup script is called foo.sh

So you could put the config file in the home dir: ~/.foo.rc
or just ~/.foo if you prefer

Another trend is to put config files in a common dir like .config (look for it, you will see that quite a few apps already use this location). So you could have your script look for ~/.config/foo

It's up to you.

I would also suggest a test at the head of your script that prompts the user to create the file if it does not exist. Just so it doesn't inexplicably crash and burn if the user hasn't created a config yet.

Hope that helps!
 
Old 06-05-2014, 02:20 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
the script itself could be stored in $HOME/bin.
this folder does not always exist by default, but if you create it it will probably be added to your $PATH.
excerpt from $HOME/.bash_profile:
Code:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
that way you can invoke the script without its full path, just like any other ol' program.
Happy bashing!
 
  


Reply



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
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
How to end the bash script using commands in bash not manually by pressing ctrl+c Sanpreet Singh Linux - Newbie 1 07-03-2013 01:04 PM
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 08:25 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:20 AM.

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
Open Source Consulting | Domain Registration