Re: Bash script problem
On Thu, Aug 05, 2021 at 01:03:16PM -0700, Gary L. Roach wrote:
> First, the IFS command sets the string separator. The default values are
> space /n and one other. The / is not among them.
Yes, we know that. The issue is that you are setting IFS for the
whole script, when you probably *should* be setting it only for a
single command.
Compare the following two blocks of commands:
IFS=/
read -ra array
vs.
IFS=/ read -ra array
The former is what *you* are doing. This sets IFS permanently, for
the duration of the script or the current subshell (or function, if
you previously declared IFS to be local inside a function).
The latter is what we keep telling you to do. You keep not doing it.
> Second, why am I separating out the Path the way I am doing? I need to check
> each level for existence then, if the level doesn't exist, create the
> directory, cd to the directory, [...]
Why can't you just mkdir -p the final directory? This creates the
parent directories as needed.
> [...] set chown and -x chmod. After that check the
> next level and repeat the process until I run out of levels.
What do you mean by "-x chmod"? A directory *needs* the +x permission bit
to be set in order to function properly.
file=/opt/foobar/share/foobar.conf
dir=${file%/*}
mkdir -p "$dir"
touch "$file"
You're doing *way* too much work. It's a gigantic X-Y problem.
> I want to use this .sh file to automatically set up the Amanda backup system
I don't know Amanda, so I can't help you with that part.
Reply to: