1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms:
3. The attempts at a solution (include all code and scripts):
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):Seneca College, Toronto, Don Frray, ULI101
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
In step 1, unless my versions of Kshell and Bash are way out dated, I do not believe this test will work:
Both Kshell and Bash treat the right hand side of the expression as a pattern, but NOT a regular expression. You're on the right track, but regardless of the value in studentid, this test will always be true.
In step 2, this dir=a2/Pictures is OK, but if the script is run from another directory your later test will fail. You might think about changing the current directory to your home directory early on.
Step 4....
First, 1 is not a valid variable name so the assignment statement
is not correct. Same for the other two assignments.
From the instructions you should not be hard coding the filenames that you are to copy. You need to disect the user number entered in step 1 and build the source filename using each digit. The hint given in the instructions should be a big clue that the cut command will make it easy to extract the desired digit (first, second or third) and then you need to use the extracted digit to build the source filename to copy.
Take a look at the manual page for the cut command and pay particular attention to the -c option.
I'm guessing that there are only 10 picture files (linux-pic0... linux-pic9) in the source directory, but if you think of there being more than one linux-pic0 file (maybe linux-pic0-a and linix-pic0-b) and how you might copy all of those using one command, you might see how you can specify the source filenames on your copy command without needing to code the whole pathname.
Sorry if this is difficult to understand, but as this is an assignment I only want to provide you with some clues that might get you onto the right path.
Thanks for the response.
The step 1 works fine and I tested the command by saving the whole thing as a file with .sh extension.
yes, you are right and I have files from 0 to 10 correspond to the last 3 digits of my student id which is 106.
The problem is i don't know what to do for step 4!
I am confused with cut command and everything seems complicated. this is almost the end of semester and I have few days to complete this assignment!
Would you please give me more hint for step 4
Thanks
Hi, I am in the same class as almirazee (found this forum through google). I'm having trouble with Step 1 and elected to go a simpler route than him. Here's my attempt:
Quote:
echo "Please enter a 3 digit number"
read numbers
if [ "$numbers" = "^[0-9][0-9][0-9]$" ]
then
echo $numbers
else
exit 1
fi
I've tried '==', -eq, quotes, no quotes and permutations of these. The condition always equals false and goes to the "else" statement. I know this because when I add "echo $numbers" above the "exit 1" in the "else", it prints it out no matter what the input from the user.... without it, it just goes back to the prompt. Similarly, if I change the condition to "!=" the condition is always true no matter the input
I know it's a syntax thing, I've got the logic part (I'm in programming). So where am I going wrong?
Hi there
Im in section B , ULI 101
Here is the possible solution of a step 1
27 echo "Enter the last tree digints of your student id:"
28
29 read num
30
31 if [[ $num =~ ^[[:digit:]][[:digit:]][[:digit:]]$ ]]; then
32 echo "Your studID = $num"
33 else
34 echo ERROR! YOU MUST TREE TYPE DIGITS ONLY!
35 exit 1
36 fi
I have a little code block (executing on AIX 7.1) that I cannot understand why the NOTFREE=0 does not appear to be assigned even though it goes through that block. This causes a unary operator issue.
#!/bin/bash
PLATFORM="AIX"
NEEDSPC=3000
set -x
if ; then
lsvg | grep -v rootvg | while... (6 Replies)
I have come across a weird behaviour in bash and would love to get to the bottom of it. If I execute echo -e "\na\nb\nc\n" at the command line, I get:
a
b
c
However, if I wrap it in an assignment such as:
A="$( echo -e "\na\nb\nc\n" )"then I get
a
b
cIt doesn't show very well,... (4 Replies)
Suppose I have a file named Stuff in the same directory as my script. Does the following assign the file Stuff to a variable?
Var="Stuff"
Why doesn't this just assign the string Stuff? Or rather how would I assign the string Stuff to a variable in this situation?
Also, what exactly is... (3 Replies)
I am going to provide a chunks of codes that I do not understand. Please help with them in a layman's terms.
1) ${DEBUG:-0}
--------------------------------------------------------------------------
2) print "${1}"
... (7 Replies)
Here's the assignment. I'll bold the parts that are rough for me. Unfortunately, that's quite a bit lol. The syntax is, of course, where my issues lie, for the most part. I don't have a lot of programming experience at all :/. I'd post what I've already done, but I'm so lost I really don't know... (1 Reply)
Hi guys,
I'm basically looking for some help with a bash script I've written. It's purpose is to assign process to individual CPU cores once that process hits 15% CPU usage or more. If it drops below 15%, it's unassigned again (using taskset).
My problem is that I can't think of a way to... (2 Replies)
Doubt #1
I have a program that I want the user to input date. When the user inputs the date, is it able to format it to system date dd-mm-yyy and then echo the value into a text file?
Doubt#2
If the above is not going to work, I tried to have the system date appear in the user input field and... (6 Replies)
I have a very tough shell program to do. Here is the assignment:
Write a non-interactive script that takes in any number of directory names as arguments and calculates and outputs the total number of blocks of disk space occupied by the ordinary files in all the directories. For example, the... (0 Replies)
Hi,
I'm writing a KSH script, and at one point, I have to call a new shell and perform some variable assignments.
I noticed that the assignment is not working.
Please see two samples below:
Command 1:
#>ksh "i=2;echo I is $i"
Output:
#>I is
Command 2:
#>ksh <<EOF
> i=2
> echo I... (7 Replies)