un=$1
is_parm()
{
if [ $# -eq 0 ]; then
return 1
else
echo "no parameters"
fi
}
is_user() {
id -u $un >> /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "$un is not a valid username"
fi
if [ "$un" = "" ]; then
return 1
else
count=$(ps -u $un | wc -l)
echo "$un has $count
processes"
fi
}
is_parm
is_user
1 #!/bin/bash 3 usrprocs() { 4 if [ ! $1 ]; then 5 echo "$1 <username>...
2-variables-galore.sh #!/bin/bash set -u greeting="Hello" name = $1 if [[ -z $name ]]; then echo "You need to tell me your name!" echo " $0 " exit -1 else echo "$greetig $name" fi while [[ $i < 4 ]]; do echo "i is currently $i" i=$((i+1)) elihw set +u exit 0 There are four (4) problems with this script. Above is an example output of the script.
Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command not found line 10: syntax error near unexpected token `then' line 10: `then' ------------------------------- #!/bin/bash if [ $# != 1 ] then echo "Usage: myScript.sh " exit 1 fi if [ -f $1 ] then awk ' BEGIN...
Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....
GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Enter course grade and units. 2. Show GPA. 3....
CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...
a) You will write a void function to get a positive integer between 1 and 12 inclusive. The twelve numbers represent the months of the year. The user will be asked to enter an integer between 1 and 12 inclusive. If the number entered by the user is not within range, an appropriate error message will be displayed, and the user will be asked to try again until a valid number is entered. b) You will write a void function...
Textual menus work by showing text items where each item is numbered. The menu would have items 1 to n. The user makes a choice, then that causes a function to run, given the user made a valid choice. If the choice is invalid an error message is shown. Whatever choices was made, after the action of that choice happens, the menu repeats, unless the menu option is to quit. Such kind of menus are displayed from the code under...
Step 3: How would you write this script in C? It needs to do the things required in step 3. 1. You have received a new batch of distinguished users; their basic information is located in newusers.tar. Inside of the tar file, there is a file called "newusers.txt" which contains a colon-separated entry for each user: the username, the uid, the GECOS information, and the user's preferred shell. Also in the tar file you will find a public key for...
Explain everything that is happening on line 125 of the script, where the roff2pdf() function is called. (Hint: sort out the function arguments and input/output redirection.) line 125: roff2pdf "$OUTPUT_TITLE" < $TMP_FILE_M > $OUTPUT_FILE #1 /bin/sh # Verify that the command line arguments are suitable if [ -z "$1" ] 11 [ $# -gt 2 ]; then echo "Usage: $0 <page> [<section>]" exit 1 1 # util is avail # Check whether a utility is available on the system. #...
Python 3: Write a function CharCount, to take a string S and a single character C, and returns the count of C (one letter) in the string S. If the letter of C is not found in S, the function returns -1. You must write your own function to do this and can not use any built-in counting functions. Use the function in main to get two inputs from the user, a sentence and a character, then show the count...