I have two instances of it being used and I am wondering what each does:
mv ~/Desktop/Service$version.tgz $service
What does the little squiggly
Then, after that that, what would
cd $service do?
The squiggly thing is called a "tilde".
It expands to your home directory.
echo ~ echo $HOME
Both statements put your home directory by itself on a line..
See bash Tilde Expansion for details.
The "squiggly" is called a tilde. It is used to refer to your home directory which on Linux, is normally
/home/username. It is also stored in the
$HOME environment variable. Expanding the
~ to the location of the home directory is the job of the shell (like zsh or bash) or file manager (like Nautilus) and not the filesystem or OS its self.
You can also use this to refer to another user's home directory. For instance, if the other user's username is
bob, you could refer to their home directory with
~bob, which will be expanded to
The first example you've given sets the variable
~, so it corresponds to your home directory. This is equivalent to
The second example copies the file
/home/username. This command is equivalent to:
mv ~/Desktop/Service$version.tgz ~
mv ~/Desktop/Service$version.tgz $HOME
mv ~/Desktop/Service$version.tgz /home/username/
The third will change the current working directory (
/home/username/. This is equivalent to:
In both #1 & #2: ~ is your home directory, so if you are qwerty it will likely be the directory /home/qwerty. So try
ls ~ to see that.
For #1: it looks to me like the variable service is being defined as your home directory.
That means after #2 has moved the tgz file from the Desktop subdirectory to your home directory, #3 then changes to the home directory.
It looks like the commands are doing the following.
Assign a variable called service to your home folder location, for example:
It moves the file from your desktop to the top level of your home directory, for example:
The script then changes the directory to the top level of the home directory.
So, all the script is doing is just cleaning up your desktop by moving the file to your
/home/user folder instead.
I'll add here that ~user also expands to [user]'s home directory, so it's not just a shortcut for your own home directory.
[guy@abox anotherdir]$ cd ~ [guy@abox ~]$ pwd /home/guy [guy@abox ~]$ cd ~john [guy@abox john]$ pwd /home/john