Let's start with clearing the terminal
Now let's execute some commands
pwd will show our current directory
ls -la will give a detailed list of files in the current directory
So far, so good. Bash also makes it possible to run some previous commands without re-typing them. Let's get the list of commands we have executed so far:
you should see something similar to:
- 1 clear
- 2 pwd
- 3 ls -la
- 4 history
So we see our command history.
Let's run something from history, say we want to repeat the clear command. It has a line number 1, so type
Notice that the is a ! sign before the number, telling shell to run command numbered 1 (which will clear the screen)
So far, we've been running commands by hand. Let's try a different approach and run a shell script in a file.
Let's create the file first. Type and run the following command:
echo "echo Hello World!" > helloworld.sh
If all goes well, you can see the file by running
You will see something similar to -rw-r--r-- 1 scrapbook scrapbook 18 Sep 28 06:06 helloworld.sh
Here please go over your notes for Week2, to understand the initial part. Later you'll notice that it is missing the "x" (execute) rights. So we cannot run it. Let's fix this:
chmod a+x helloworld.sh
This will give execute right to everyone. Do
ls -la so see that x values are visible for this file.
If everything is ok, let's run this script:
Why did we use ./ ? Remember . means the current directory, so ./ means "within the current directory". So, we tell bash to run the script in the current directory.
You should see "Hello World!" as the output. If that's the case, you have succceed.