Sponsored Content
Homework and Emergencies Homework & Coursework Questions Bash Shell Programming assignment. Post 302543424 by agama on Sunday 31st of July 2011 06:00:45 PM
Old 07-31-2011
These are my observations about your attempt:

In step 1, unless my versions of Kshell and Bash are way out dated, I do not believe this test will work:

Code:
elif [[ "$studentid" != ^[0-9][0-9][0-9]$ ]]

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
Code:
1=~/a2/Pictures/linux-pic1-clustertux.gif

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.
This User Gave Thanks to agama For This Post:
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
RENAME(1)							   User Commands							 RENAME(1)

NAME
rename - rename files SYNOPSIS
rename [options] expression replacement file... DESCRIPTION
rename will rename the specified files by replacing the first occurrence of expression in their name by replacement. OPTIONS
-v, --verbose Give visual feedback which files where renamed, if any. -V, --version Display version information and exit. -s, --symlink Peform rename on symlink target -h, --help Display help text and exit. EXAMPLES
Given the files foo1, ..., foo9, foo10, ..., foo278, the commands rename foo foo0 foo? rename foo foo0 foo?? will turn them into foo001, ..., foo009, foo010, ..., foo278. And rename .htm .html *.htm will fix the extension of your html files. WARNING
The renaming has no safeguards. If the user has permission to rewrite file names, the command will perform the action without any ques- tions. For example, the result can be quite drastic when the command is run as root in the /lib directory. Always make a backup before running the command, unless you truly know what you are doing. SEE ALSO
mmv(1), mv(1) AVAILABILITY
The rename command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux June 2011 RENAME(1)
All times are GMT -4. The time now is 10:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy