Sponsored Content
Homework and Emergencies Homework & Coursework Questions 1st yr Exam revision thread - Scripts, C, Commands Post 302812251 by murphy on Saturday 25th of May 2013 12:13:23 PM
Old 05-25-2013
1st yr Exam revision thread - Scripts, C, Commands

Hello, I have an exam for 1st year Linux and Unix programming coming up in a week and I need some help going over the past exams, I want to make sure I'm getting the right answers in the past exams to ensure full marks.

The internet is a distraction so making this thread will hopefully help me focus! Also, it will be good revision for anyone else in the same boat, while hopfully helping me commit it to memory and understand it better, and the questions should be pretty easy Smilie

1. Write a bash script for the minimum program that works as follows:
Code:
$ min  2 3
The minimum of 2 and 3 is 2

Heres my answer:
Code:
#!/bin/bash
 
if 
$1 < $2
echo "The minimum of $1 and $2 is $1"
else
echo "The minimum of $1 and $2 is $2"
fi

Pseudocode:
If
arg1 is less than arg2
output: "the minimum of arg1 and arg2 is arg1"
else
output: "the minimum of arg1 and arg2 is arg2"

Is my algorithm correct? The program compiles, but when I run it I get syntax error. What is the correct syntax please help.

---------- Post updated at 11:13 AM ---------- Previous update was at 10:43 AM ----------

Figured it out Smilie

Code:
if
[[ "$1" < "$2" ]];
then
echo "The minimum of $1 and $2 is $1"
else
echo "The minimum of $1 and $2 is $2"
fi

It works and outputs correctly. Do you think this answer would get full marks in an exam?

2. What is the search path for the shell?

Last edited by murphy; 05-25-2013 at 01:45 PM..
 

9 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

deletion of thread backup scripts!!!

I have posted a thread backup scripts. Can you assist in deletion of the said thread. Thanks and Regds Kamlesh (1 Reply)
Discussion started by: kamlesh_p
1 Replies

2. Shell Programming and Scripting

Running shell scripts automatically without using Batch or at commands

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)
Discussion started by: ritzwan0
3 Replies

3. Shell Programming and Scripting

writing shell scripts of commands

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)
Discussion started by: rahul_11d
0 Replies

4. UNIX for Dummies Questions & Answers

1st time with scripts

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)
Discussion started by: Jeonsah
3 Replies

5. Shell Programming and Scripting

Bash scripts as commands

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)
Discussion started by: Leo_Boon
1 Replies

6. Homework & Coursework Questions

Calculating Total and Averages with awk Commands & Scripts

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)
Discussion started by: RedJohn
8 Replies

7. UNIX for Dummies Questions & Answers

Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts

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)
Discussion started by: bikerboy
7 Replies

8. UNIX for Beginners Questions & Answers

UNIX commands and scripts

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)
Discussion started by: edujs7
1 Replies

9. UNIX for Beginners Questions & Answers

Saltstack commands inside bash scripts donā€™t work

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)
Discussion started by: gurudewa
8 Replies
LOGFILE(1)							       mrtg								LOGFILE(1)

NAME
logfile - description of the mrtg-2 logfile format SYNOPSIS
This document provides a description of the contents of the mrtg-2 logfile. OVERVIEW
The logfile consists of two main sections. A very short one at the beginning: The first Line It stores the traffic counters from the most recent run of mrtg The rest of the File Stores past traffic rate averates and maxima at increassing intervals The first number on each line is a unix time stamp. It represents the number of seconds since 1970. DETAILS
The first Line The first line has 3 numbers which are: A (1st column) A timestamp of when MRTG last ran for this interface. The timestamp is the number of non-skip seconds passed since the standard UNIX "epoch" of midnight on 1st of January 1970 GMT. B (2nd column) The "incoming bytes counter" value. C (3rd column) The "outgoing bytes counter" value. The rest of the File The second and remaining lines of the file 5 numbers which are: A (1st column) The Unix timestamp for the point in time the data on this line is relevant. Note that the interval between timestamps increases as you prograss through the file. At first it is 5 minutes and at the end it is one day between two lines. This timestamp may be converted in EXCEL by using the following formula: =(x+y)/86400+DATE(1970,1,1) you can also ask perl to help by typing perl -e 'print scalar localtime(x)," "' x is the unix timestamp and y is the offset in seconds from UTC. (Perl knows y). B (2nd column) The average incoming transfer rate in bytes per second. This is valid for the time between the A value of the current line and the A value of the previous line. C (3rd column) The average outgoing transfer rate in bytes per second since the previous measurement. D (4th column) The maximum incoming transfer rate in bytes per second for the current interval. This is calculated from all the updates which have occured in the current interval. If the current interval is 1 hour, and updates have occured every 5 minutes, it will be the biggest 5 minute transferrate seen during the hour. E (5th column) The maximum outgoing transfer rate in bytes per second for the current interval. AUTHOR
Butch Kemper <kemper@bihs.net> and Tobias Oetiker <oetiker@ee.ethz.ch> 3rd Berkeley Distribution 2.9.17 LOGFILE(1)
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy