Few helpful links to get started with bash scripting
Few common errors
Practice Questions
- Print "Hello" on one line and print "World" on next line using echo command. You can use multiple echo commands.
- Print "Hello" on one line and print "World" on next line using single echo command.
- Print "Hello World!" on one line. Constraint: Use atleast 2 echo commands in your script. (Hint: echo -n )
- Create an array of 10 integers (0 to 9) and print the square of each element in this array (without using loops)
- Create an array of 10 integers (0 to 9) and print the square of each element in this array by using loops
- Create a file named scores.txt in current directory
- Create a file named scores.txt in current directory such that you use absolute path name to create it. Eg: "/home/niraj/Documents/scores.txt"
- Print the name of each file in current directory
- Print the name of each file in current directory such that "_checked" is appended to these filenames. Eg: If there are 3 files: a.txt, b.txt, c.txt, then your output should be a.txt_checked. b.txt_checked, c.txt_checked
- Print the count of number of files in current directory
- Print the count of number of files in current directory. If count is odd, print "Odd", if even, print "Even"
- Print name of files which are directories in current directory
- Find total number of directories in your home directory and '/boot' directory
- Make a directory named 'temp' in your current directory. Create 1000 files in 'temp' directory such that filenames are "1", "2", "3", .. "1000"
- Create a bash script that takes 2 arguments: 1) path to directory 'd', 2) some string 's'. Your script should internally list the contents of the directory 'd' and then check whether string 's' is part of each filename listed (using grep). If one or more matches are found by grep, print 'Match Found!', else print 'No Match Found!'. Constraint: You have to use $? to check whether grep succedded or not and then print the required messages appropriately.
- Create a shell script and pin it to core 0 from within the script.