Help with script to make a directory, change directory, download a file, then back out of that directory

All,

I'm trying to write a script that will create a folder, go into that folder, create another folder, go into that folder, download files, back out of that folder, create a new folder, go into that folder, download files, back out of that folder, back out of the folder again to I'm returned to the root of the folder I started from. This then would repeat again; I feel like if I can get the first iteration correct then it'll be easy to just copy/paste to run over and over again as needed.

Here's what I have (and isn't 100% working):

#Main Folder 1
mkdir 'XXX'
cd 'XXX'
##Sub Folder 1
mkdir 'YYY'
cd 'YYY'
(Download File command here - working properly in testing)
cd ..
##Sub Folder 2
mkdir 'ZZZ'
cd 'ZZZ'
(Download File command here - working properly in testing)
cd ..
cd ..

The issues I'm facing are this:

  1. When the script creates the folder it has (what looks like) a • at the end of the folder name
  2. The script doesn't change the directory "up" one level and then again two levels

I've searched and not found anything about the first issue. It seems that "cd .." won't work in a script (as it throws the error " cd: can't cd to .." and there's something else I should use but pinning down what that is has been difficult.

Thanks in advance!

15

1 Answer

A very simple example that will help you is :

# OPTION 1
CURDIR=$( pwd )
# OPTION 2
CURDIR=$PWD
D1="XXXXXX"
D2="YYYYYY"
mkdir $D1
cd $D1
mkdir "foo_bar"
cd "foo_bar"
cd $CURDIR
mkdir $D2

3 things to know about this :

1.a) pwd is a command to display the current name of current folder

1.b) $(....) is a way to capture the output of command and transform into a string

1.c) CURDIR is a arbitrary name i choose

  1. $PWD is a variable usually populated with the current dir
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like