Bash Shell Programming assignment.

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Bash Shell Programming assignment.
# 8  
Old 08-01-2011
Quote:
Originally Posted by almirzaee
Hi
I can't write this loop! I did my best and still have problem on this step! could you give me the solution fro step 4.
Thanks
Because this is an assignment I don't think anybody here will hand you the solution. I'm sure if you were to post what you've tried, or even pseudo code, people would offer suggestions as to what might be causing you to get stuck.
This User Gave Thanks to agama For This Post:
# 9  
Old 08-01-2011
Quote:
Originally Posted by almirzaee
Hi
I can't write this loop! I did my best and still have problem on this step! could you give me the solution fro step 4.
Thanks
Code:
num="109"
for ((i=0;i<3;i++)); do
    echo ${num:$i:1};
done

Assignment said use cut ? hmm.. see agama's post.
This User Gave Thanks to neutronscott For This Post:
# 10  
Old 08-02-2011
Thanks for reply, but I need step 4 solution my friend.
if possible....
# 11  
Old 08-02-2011
Step 7

Does anybody have a hint for step 7 part (1)
### STEP 7
###=================================
### Part (1):
### Display all the non-hidden files in your ~/a2/Pictures that have a
### filename that consists of one digit only
I tried ls | grep [0-9] and [0-9]{1} and so on but it always displays one and more digit.

Thanks
# 12  
Old 08-02-2011
echo path/to/[0-9]
This User Gave Thanks to Corona688 For This Post:
# 13  
Old 08-02-2011
Google makes miracles )

Here one of the solution for #1

Code:
read -p "Write your student ID: " ID              #write your variable $ID, you can use yours
if ! echo $ID | egrep "^[0-9][0-9][0-9]$"          
then
   echo "Write your ID, I'm NOT joking"
   exit 1
fi


Last edited by XYU; 08-02-2011 at 10:02 PM..
This User Gave Thanks to XYU For This Post:
# 14  
Old 08-03-2011
My understanding of the assignment was that the ID was passed as $1...

Code:
When this script is run, one parameter/argument is passed to the script.

The step4 solution you desire is nothing more than the loop

Code:
id=109
for ((i = 1; i <= 3; i++)); do
        digit=$(echo $id | cut -c${i})
done

with the copy inside of it
Code:
cp ~a2/Pictures/linux-pic${digit} ~/public_html/

This User Gave Thanks to neutronscott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash variable assignment failure/unary operator expected

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

2. Shell Programming and Scripting

Loosing trailing new line in Bash var assignment

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

3. Shell Programming and Scripting

Bash variable assignment question

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

4. Shell Programming and Scripting

Chunks of bash shell programming

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

5. Shell Programming and Scripting

Making a bash script and small C program for a homework assignment

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

6. Shell Programming and Scripting

CPU assignment bash script

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

7. UNIX for Dummies Questions & Answers

Help with date command in bash shell programming

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

8. Shell Programming and Scripting

shell programming assignment

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

9. Shell Programming and Scripting

variable assignment in new shell

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)
Discussion started by: maverick80
7 Replies
Login or Register to Ask a Question