User Tools

Site Tools


bash_class2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bash_class2 [2013/05/10 17:46]
Rob Whyte created
bash_class2 [2019/02/09 10:31] (current)
Line 2: Line 2:
    
 Storm Hello everyone Storm Hello everyone
-  
-Storm just 3 minutes to go 
-  
-Mike Cool storm, I am ready when you are.  I have Vinux booted in my VM. 
-  
-Storm cool 
-  
-Storm Ok, time to get rolling I guess. 
    
 Storm So last time we left off after learning about the arguments that can be passed into scripts $1 through $9 Storm So last time we left off after learning about the arguments that can be passed into scripts $1 through $9
Line 15: Line 7:
 Storm I would just like to add a couple more things to that. Storm I would just like to add a couple more things to that.
    
-Storm $0 is the name of the script itself. so, if you were to open our hello.sh file from last time. It should be in your intro-to-bash directory. +Storm $0 is the name of the script itself. so, if you were to open our hello.sh file from last time. It should be in your intro-to-bash directory, and add to it: 
-Storm add echo  +  echo "$0" 
- "$0" just before the exit 0 line +  
-  echo $0+Storm just before the exit 0 line
    
 Storm and then save and execute it with: Storm and then save and execute it with:
Line 27: Line 19:
    ./hello.sh    ./hello.sh
    
-Mike I see. +Storm the reason it only says hello on the first line is because no arguments were passed to it.
-  +
-Storm the reason it only says hello on the first line is because no arguments got passed to it+
-  +
-Storm The other thing I wanted to mension is $@ +
-  +
-Storm It refers to all arguments  passed to the program. +
-  +
-Mike What would be a good example of when to use that? +
-  +
-Storm remember how we had to pass arguments with spaces inside quotes? And how we are limited by $1 through $9? +
-  +
-Mike yes +
-  +
-Mike I remember seeing that from when I viewed the log.+
    
 +Storm The other thing I wanted to mension is $@. It refers to all arguments  passed to the program. Remember how we had to pass arguments with spaces inside quotes? And how we are limited by $1 through $9?
 +  
 Storm This takes away that limit. You can have as many arguments as you want. Storm This takes away that limit. You can have as many arguments as you want.
    
-Mike I see. +Storm If you change all the variables $1, $2, $3, etc to $@ in hello.sh and save it you can test this for yourself. Do something like 
-  +
-Storm If you change all the variables $1, $2, $3, etc to $@ +
-  +
-Storm in hello.sh and save it you can test this for yourself. +
-  +
-Storm do something like +
   ./hello.sh it is a very beautiful day and I am glad to share it with you   ./hello.sh it is a very beautiful day and I am glad to share it with you
    
-Storm no quotes required.+Storm no quotes required. But you should get the whole message even though there are spaces.
    
-Storm but you should get the whole message even though there are spaces.+Storm This comes in even more useful when we start getting in to arrays. Now it's time for redirection.
    
-Mike We should probably create a place to post pass source code for people who did not receive it, since copying from   +Storm Did you know that Linux has a black hole? You can use a thing called redirection to send text/output to different places. If you type 
-the logs can be a bit tedious. +
-  +
-Mike I will need to play catch-up, for example. +
-  +
-Storm This comes in even more useful when we start getting in to arrays. +
-  +
-Storm Mike: sounds like a good idea. +
-  +
-Storm And now it's time for redirection. +
-  +
-Storm Did you know that Linux has a black hole? +
-  +
-Mike No, what do you mean by black hole? +
-  +
-Storm You can use a thing called redirection to send text/output to different places. +
-  +
-Storm if you type +
   echo "hello"    echo "hello" 
    
-Storm   you will get the output hello on the screen. +Storm   you will get the output hello on the screen. Instead try:
-  +
-Storm now try instead+
   echo "hello world" > /dev/null   echo "hello world" > /dev/null
    
-Storm /dev/null is the black hole I was talking about. Anything redirected to /dev/null will vanish without a trace. +Storm /dev/null is the black hole I was talking about. Anything redirected to /dev/null will vanish without a trace. So:
-  +
-Storm so+
   echo "hello world" > /dev/null    echo "hello world" > /dev/null 
    
-Storm does nothing except put you back at your prompt +Storm does nothing except put you back at your prompt /dev/null is the perfect place to send say an X wife or something lol 
-  +  
-Mike Then what is the main purpose of using /dev/nul? +
-  +
-Burt so I change null for somewhere, and I don't have that hole in my pocket anymore?>? +
-  +
-Storm It is for things like redirecting text you don't want to see, useful in cron jobs, etc +
-  +
-Storm /dev/null is the perfect place to send say an X wife or something lol +
-  +
-Storm there, a little shameless advertising. +
- +
 Storm You can also use redirection for sending output to a file. Storm You can also use redirection for sending output to a file.
    
 Storm If you are back to your prompt in your intro-to-bash directory do the following Storm If you are back to your prompt in your intro-to-bash directory do the following
   echo "I love Intro to Bash" > test.txt   echo "I love Intro to Bash" > test.txt
-  
-Mike I need to create my intro-to-bash. mkdir intro-to-bash, correct? 
-  
-Mike I can do that from my home dir? 
-  
-Storm yes, in your home dir do: 
-  mkdir intro-to-bash 
-  
-Storm then to get to it 
-  cd intro-to-bash 
    
 Storm when you have completed the echo command you can view the  contents of the file by typing: Storm when you have completed the echo command you can view the  contents of the file by typing:
bash_class2.txt · Last modified: 2019/02/09 10:31 (external edit)