PHYS 210 ASSIGNMENT 3: HELP

From WeKey
Jump to navigationJump to search

PHYS 210 WIKI --> PHYS 210 HOMEWORK --> here


I'm having trouble with the format converting bash script. The biggest difficulty is in how do I get my script to understand what a user is inputting. The file that the user wants to convert can be named anything, and so I don't get how to make my script understand that whatever file it is, it's got to convert that into pdf.

I suspect that it's something like %& with a * in there but I'm still lost. Any help on this will be appreciated greatly!!! S44535078 02:29, 21 September 2008 (PDT) (actually signed post on 22nd..)

Please "date & sign" your entries by ending them with four consecutive tildes ("~") -- Jess 07:55, 21 September 2008 (PDT)

You should look at the usage manual section of www.imagemagick.org to get familiar with the way ImageMagick works, and then maybe try and use some of its commands in the terminal (in our case the command is of the form convert file1.ext1 file2.ext2).
(To get quick help on the syntax and options of convert, just enter convert on the command line, with no arguments, and it will print several pages of help.) -- Jess 10:11, 21 September 2008 (PDT)
When you use a command in that format, everything after the first word (which invokes the command) is an input argument. As far as your shell script is concerned, these can be referred to as variables $1, $2, $3, and so on ($# is the number of such variables sent as input). In our case the only argument is the image file name in the format file.extension because the problem already defined the second argument in the convert command to be file.pdf. So the file name that's being supplied by the user in our case will be $1 in the script. To get file out of file.ext you can assign a variable in the script that cuts a part of the argument off: fn=`echo $1 | cut -d "." -f1` (this was on the whiteboard last lab, and fn is the variable). I think you should try and see what echo $1 | cut -d "." -f1 does on its own in the terminal, and maybe play with the other cut options as well (change the delimiter character in " ", change f1 to f2, etc.).
There are other ways to parse file.ext and extract the part to the left of the period, but now that I've seen it I like the cut method better, because it is more mnemonic (albeit more wordy). Both will be described on the homework solutions to be posted Tuesday. -- Jess 10:11, 21 September 2008 (PDT)

I'm not sure if that's exactly what you were asking, so I hope I gave the answer somewhere in there. S48394076 08:23, 21 September 2008 (PDT)

In assignment 4, do you want us to generate a list of factorials? Or do you want us to extract a list of factorials. highknees 14:49, 22 September 2008 (PDT) Extract from where? I don't understand your question, but I'm pretty sure the answer is "generate". -- Jess 18:00, 22 September 2008 (PDT)

I'm having trouble checking that the input for my factorial script is all numbers. So far I've got something along the lines of if [[ "$1" = [0-9] ]] ... but that only tests the first character. I think there is some operator that would go in the format [0-9]something[0-9] that would test all the characters successively. Ideally if would have just used =~ but our version of bash doesn't seem to support it (bash 3.0 from 2004 is supposed to support the "contains" operator).

Anybody solved that issue yet? S48394076 16:55, 22 September 2008 (PDT)

This probably doesn't need to be tested explicitly. I believe anything that is not an integer will either generate an error message (which serves your purpose fine) or be interpreted as a zero, which may also be OK. -- Jess 18:00, 22 September 2008 (PDT)

Moved from P210 WIKI: talk page:

Hello,

I was wondering if anyone was around, and willing, this weekend to help me with assignmnet 3. I am completely new to computer land, except the basic necessities like MSN and Facebook, jk.

Please let me know,

Shauna