From 5c8942f7bcb02a59d1e0acefb0069e80de57e01e Mon Sep 17 00:00:00 2001 From: viv1 Date: Mon, 19 Oct 2015 02:50:55 +0530 Subject: [bash/en]...Added info on changing directories --- bash.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 211d2944..dfbf9a89 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -130,6 +130,15 @@ ls -l # Lists every file and directory on a separate line # .txt files in the current directory: ls -l | grep "\.txt" +# Since bash works in the context of a current directory, you might want to +# run your command in some other directory. We have cd for changing location: +cd ~ # change to home directory +cd .. # go up one directory + # (^^say, from /home/username/Downloads to /home/username) +cd /home/username/Documents # change to specified directory +cd ~/Documents/.. # still in home directory..isn't it?? + + # You can redirect command input and output (stdin, stdout, and stderr). # Read from stdin until ^EOF$ and overwrite hello.py with the lines # between "EOF": -- cgit v1.2.3 From f94dea8379b5e7a28990eac371f9c9cca19ab472 Mon Sep 17 00:00:00 2001 From: Matteo Baglini Date: Tue, 12 Jan 2016 00:32:03 +0100 Subject: Use proper string comparison syntax --- bash.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bash.html.markdown') diff --git a/bash.html.markdown b/bash.html.markdown index 211d2944..bd2d5984 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -83,7 +83,7 @@ echo Hello, $Name! # We have the usual if structure: # use 'man test' for more info about conditionals -if [ $Name -ne $USER ] +if [ $Name != $USER ] then echo "Your name isn't your username" else @@ -91,12 +91,12 @@ else fi # NOTE: if $Name is empty, bash sees the above condition as: -if [ -ne $USER ] +if [ != $USER ] # which is invalid syntax # so the "safe" way to use potentially empty variables in bash is: -if [ "$Name" -ne $USER ] ... +if [ "$Name" != $USER ] ... # which, when $Name is empty, is seen by bash as: -if [ "" -ne $USER ] ... +if [ "" != $USER ] ... # which works as expected # There is also conditional execution -- cgit v1.2.3