It isn't obvious to me that this shouldn't be treated as homework and be required to have been posted in the Homework & Coursework Questions forum and adhere to the special rules associated with that forum. I'll leave that determination to the moderators, but I'll treat my responses as if it had been posted there.
I had never seen an if statement coded this way, but after looking at the grammar for the shell, it is a valid format. More common ways of coding if statements would be:
or
Although indentation is not required by the shell (and it may seem unimportant for a trivial case like this script), when the code in the true and false sections becomes more complex, indentation will make your code much easier to read. I strongly suggest that you get into the habit of always using a consistent indentation style and stick with it no matter how trivial the script is.
Other than using 2 and 4 as operands to your script, what values have you used to convince yourself that this script is working correctly? When you issue the commands:
do you get what you expected?
Do you intend for your script to compare numeric values or alphanumeric string values?
Thanks for the reply I appreciate it, I also wasn't sure if this should be in the homework section, I didn't want to clog it up as I want to keep this alive for a week. If the mods wants to move it they can, and some of the questions I am going to ask are pretty basic
My program is working fine, with any values I throw at it.
Will output:
The same when the numbers are reversed, I'm happy with that, also I will remember to indent more,ty.
Heres some more questions, are the ansers I've given correct? Will they get all the marks?
a) What is the purpose of the shell? The shell is a program that interprets commands and acts as an intermediary between the user and the inner workings of the operating system. b) What is the search path for the shell? The search path is contained in the C shell “path” variable. Like all C shell variables, it can be referenced by placing a dollar sign in front of the name. The current search path can be printed with % echo $path. The search path is also a component of the environment which is passed from process to process, independent of the shell. c) Using the curses library, what commands would you use to - Clear the whole screen. clear(); - Clear only the first two lines of the screen. Deleteln?? I am unsure about what command to use in the last one, theres seems to be alot of commands in the curses library for removing lines, but I can't seem to find the specific one that deletes the first two lines. Any hints?
I have been trying to run a unix script which contains many sql statements.I need to run this script every monday morning. I tried to run on command prompt, it works fine. But while I run it via batch or at command., it returns with library module could not be loaded (libcompat.1.o could not be... (3 Replies)
can anyone help me in writing a shell script to visualize how simple commands work and on what logic. For Eg: ls command how it lists out all the files and directories, need to write a simple script based on the commands source code.:D (0 Replies)
Hello everyone. I am new to writing scripts and I am trying to figure out how to get it to work on a unix system. I am currently using windows xp to write my scripts. My questions are:
1. If the scripts are writtin in Wordpad, what do I save them as before converting them on unix?
2. After... (3 Replies)
Hello,
the bulk of my work is run by scripts. An example is as such:
#!/bin/bash
awk '{print first line}' Input.in > Intermediate.ter
awk '{print second line}' Input.in > Intermediate_2.ter
command Intermediate.ter Intermediate_2.ter > Output.out
It works the way I want it to, but it's not... (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Write an awk script(company.awk) for the workers file to find the number of workers of each departman, total... (8 Replies)
I have a shell script which executes to write html codes into a text file. My next step is to email the text file so that receiving person (people who i send email to) should be able to see pie/chart or bar graph (whatever i design in my code) in their email. Following is the example of a sample... (7 Replies)
Hi guys,
Hoping someone can help with the below - involves basic commands and some scripting. Thanks so much in advance for your amazing time and help.
3. The file /etc/profile contains the default initialization options for your shell.
Produce a unique list of all variables with uppercase... (1 Reply)
In a Redhat Linux environment, I could run salt commands on the $ prompt but not inside my bash scripts.
It will say command not found and the $PATH variable is exactly the same outside and inside the script.
!#/usr/bin/bash
echo “running”¯
salt "*" cmd.run ‘ls'
exit
Output:-... (8 Replies)