Results 1 to 8 of 8
Im new to scripting and i have no idea even where to start with this program. I figured out some of the command line to run a bash script but ...
- 10-27-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Bash and Powershell scripting help
Im new to scripting and i have no idea even where to start with this program. I figured out some of the command line to run a bash script but i don't know how i would access the bash script that i make, like do i have to put it into its own directory or put it on the linux server and how would i do this?
I)Write a shell script program (2 versions) to present a sample test question, read the response, present a result and record the user, question and answer information in a transaction log file. The presentation will look like:
Hello name.
Here is the text for my test question.
Please select the correct answer from the choices below.
A) choice 1 … or T for true/false questions
B) choice 2 … or F for true/false questions.
C) choice 3
D) all of the above … or some combination of the above
E) none of the above
Choice:
The specifications are:
A) The programming language used must be BASH and POWERSHELL.
B) Clear the screen and present a welcome message that includes the user name of the individual running the script. This information can be obtained using a command line utility or from an environment variable.
C) Present a sample test question.
D) Present five choices for multiple choice based questions … or … two choices for true-false based questions.
E) Present a prompt asking the user for their selection.
F) Collect the response and determine if the correct choice was made.
G) Clear the screen and present the results.
H) Save the user name, question text, actual answer and given choice to some file named: mytestq. This task must preserve the results of previous attempts.
I) Prompt the user asking if they would like to try again or exit.
J) With the choice to exit, terminate the script gracefully.
K) With the choice for another try, re-present the user name, question, choices and answer prompt. Continue on with processing the information from step D.
- 10-27-2008 #2Just Joined!
- Join Date
- Oct 2008
- Posts
- 3
You know that Powershell does not run natively on Linux right?
- 10-27-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Well, there you are: a starting point and much more.
Advanced Bash-Scripting Guide
That's for bash, I never heard of powershell.
- 10-27-2008 #4Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Powershell is for windows but i have to write a script for both BASH and Poweshell
- 10-28-2008 #5Just Joined!
- Join Date
- Oct 2008
- Posts
- 10
From what you have said, I suppose that POWERSHELL has the same structure that BASH, but it relies on window platform.
So, once you had written your BASH script you only have to add a CR before each LF and your script would be then windows compliant
- 10-28-2008 #6Just Joined!
- Join Date
- Oct 2008
- Posts
- 3
Powershell and bash are not even close to being the same language. They differ at the most basic levels. For instance, bash passes string data along the pipe. Powershell passes actual objects. Powershell is built on the .Net framework. Bash essentially provides a place to tie together all the little *nix utils.
- 10-28-2008 #7Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I know nothing about powershell, as I already said. But even if it had a bash-like syntax, which seems not to be the case, there's no way that it can run an unmodified bash shell unless powershell has a builting for every standard core tool amongst those that are commonly used on scripting.
I am not sure I understand ok the OP. If he means "a single script that can run on powershell AND bash", I guess that the response is that's impossible. Otherwise, if you means "two scripts, one for powershell and another for bash" then it's just a matter of learning to use the shells. I already provided a link with all you need to learn bash scripting.
- 10-28-2008 #8Just Joined!
- Join Date
- Oct 2008
- Posts
- 3
First, this sounds like homework to me and I don't know what the forum policy regarding homework is, so I hope I'm not breaking any rules here. Second, from the original posts there are supposed to be two separate scripts.
Below I will post a powershell script that just barely meets the requirements as stated. If I were grading it as homework, I would give it at best a C. The OP should take it as a starting point and make it much more robust.
Code:$continue = $true while($continue) { Clear-Host Write-Host "Welcome $env:USERNAME. Would you like to play a game?" Write-Host "This script meets your needs:" Write-Host "A) True" Write-Host "B) False" $answer = Read-Host Clear-Host if ($answer.ToUpper() -eq "A") { Write-Host "That is the correct answer" }else { Write-Host "That is the wrong answer" } "$env:USERNAME, This Script meets your needs:, A) True, B) False, $($answer.ToUpper())" | Out-File mytestq -append Write-Host "Would you like to play again?" $playagain = Read-Host "(Y - Yes or N - No)" if ($playagain.ToUpper() -eq "N") { $continue = $false } }


Reply With Quote
