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
CALL_USER_FUNC_ARRAY(3) 						 1						   CALL_USER_FUNC_ARRAY(3)

call_user_func_array - Call a callback with an array of parameters

SYNOPSIS
mixed call_user_func_array (callable $callback, array $param_arr) DESCRIPTION
Calls the $callback given by the first parameter with the parameters in $param_arr. PARAMETERS
o $callback - The callable to be called. o $param_arr - The parameters to be passed to the callback, as an indexed array. RETURN VALUES
Returns the return value of the callback, or FALSE on error. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The interpretation of object oriented keywords | | | like parent and self has changed. Previously, | | | calling them using the double colon syntax would | | | emit an E_STRICT warning because they were inter- | | | preted as static. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 call_user_func_array(3) example <?php function foobar($arg, $arg2) { echo __FUNCTION__, " got $arg and $arg2 "; } class foo { function bar($arg, $arg2) { echo __METHOD__, " got $arg and $arg2 "; } } // Call the foobar() function with 2 arguments call_user_func_array("foobar", array("one", "two")); // Call the $foo->bar() method with 2 arguments $foo = new foo; call_user_func_array(array($foo, "bar"), array("three", "four")); ?> The above example will output something similar to: foobar got one and two foo::bar got three and four Example #2 call_user_func_array(3) using namespace name <?php namespace Foobar; class Foo { static public function test($name) { print "Hello {$name}! "; } } // As of PHP 5.3.0 call_user_func_array(__NAMESPACE__ .'Foo::test', array('Hannes')); // As of PHP 5.3.0 call_user_func_array(array(__NAMESPACE__ .'Foo', 'test'), array('Philip')); ?> The above example will output something similar to: Hello Hannes! Hello Philip! Example #3 Using lambda function <?php $func = function($arg1, $arg2) { return $arg1 * $arg2; }; var_dump(call_user_func_array($func, array(2, 4))); /* As of PHP 5.3.0 */ ?> The above example will output: int(8) NOTES
Note Before PHP 5.4, referenced variables in $param_arr are passed to the function by reference, regardless of whether the function expects the respective parameter to be passed by reference. This form of call-time pass by reference does not emit a deprecation notice, but it is nonetheless deprecated, and has been removed in PHP 5.4. Furthermore, this does not apply to internal functions, for which the function signature is honored. Passing by value when the function expects a parameter by reference results in a warn- ing and having call_user_func(3) return FALSE (there is, however, an exception for passed values with reference count = 1, such as in literals, as these can be turned into references without ill effects -- but also without writes to that value having any effect --; do not rely in this behavior, though, as the reference count is an implementation detail and the soundness of this behavior is questionable). Note Callbacks registered with functions such as call_user_func(3) and call_user_func_array(3) will not be called if there is an uncaught exception thrown in a previous callback. SEE ALSO
call_user_func(3), information about the callback type, ReflectionFunction::invokeArgs, ReflectionMethod::invokeArgs. PHP Documentation Group CALL_USER_FUNC_ARRAY(3)
All times are GMT -4. The time now is 04:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy