[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Script does not do what it is told to do



On Fri, Oct 25, 2019 at 09:33:51AM +0200, john doe wrote:
> On 10/25/2019 9:16 AM, tomas@tuxteam.de wrote:
> > On Fri, Oct 25, 2019 at 02:40:00AM +0200, deloptes wrote:
> >> Ken Heard wrote:
> >>
> >>> Whenever I run this script -- or several others like it
> >>>
> >>> #!/bin/bash
> >>> # Script to back up all browser files in directory /home/ken/mozilla.
> >>> STARTDIR=$PWD
> >>> cd /home/ken
> >>> tar -czf /media/fde/backups/kbrowsers.tgz  --exclude-caches \
> >>> --wildcards -T docs/tarlists/kbrowsers.lst
> >>> cd "$STARTDIR"
> >>>
> >>> it returns the following:
> >>>
> >>
> >> this is not possible because in the script you tell tar to create archive
> >> in /media/fde/backups/
> >
> > Possibly /media/fde is a (broken) symbolic link to /media/ssda?
> >
> > Besides (but this probably hasn't to do with your failure):
> > what are you trying to achieve with 'STARTDIR=$PWD' and then
> > 'cd "$STARTDIR"'?
> >
> 
> Given that you are using bash, my guess is that the below should do what
> you want:
> 
> STARTDIR=$(dirname $_)
> cd $STARTDIR || exit $?

My point is that all of this is unnecessary. For one, tar doesn't
change the current working directory all by itself. For two, if
all of that is run as a subshell, whatever change wouldn't propagate
"upstream".

Occam's razor.

Cheers
-- t

Attachment: signature.asc
Description: Digital signature


Reply to: