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:
- When the script creates the folder it has (what looks like) a • at the end of the folder name
- 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!
151 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 $D23 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
$PWDis a variable usually populated with the current dir