bash

making graphs with a shell script

i need to make a graph with numeric values in a time period, the values represent online users in a web page. the script will be exectued with cron every 30 mins and the needed html file will be downloaded with wget. but there are some yet unanswered questions & problems: -i need to get just the numeric value from html code (but grep r...

Bash Shell Scripting Errors: ./myDemo: 56: Syntax error: Unterminated quoted string [EDITED]

Could someone take a look at this code and find out what's wrong with it? #!/bin/sh while : do echo " Select one of the following options:" echo " d or D) Display today's date and time" echo " l or L) List the contents of the present working directory" echo " w or W) See who is logged in" echo " p or P) Print the pre...

How can the last command's wall time be put in the Bash prompt?

Is there a way to embed the last command's elapsed wall time in a Bash prompt? I'm hoping for something that would look like this: [last: 0s][/my/dir]$ sleep 10 [last: 10s][/my/dir]$ Background I often run long data-crunching jobs and it's useful to know how long they've taken so I can estimate how long it will take for future jobs....

Bash environment variables and finding installation directories

I have a Bash script that basically initializes an application and sets parameters. One of these parameters is the location to OpenOffice. Now OpenOffice doesn't set an environment variable when you install it. What is the best method of finding the location of an application installed and caching that information so you don't have to d...

More simple math help in bash!

In the same thread as this question, I am giving this another shot and ask SO to help address how I should take care of this problem. I'm writing a bash script which needs to perform the following: I have a circle in x and y with radius r. I specify resolution which is the distance between points I'm checking. I need to loop over x and...

How to get $this->translate('Content') => Content in a Textfile

I am looking for a shell script which scans a direcotry and all its subdirectories for .php and .phtml files. Within these files, I am looking for $this->translate('') statements (also $this->view->translate('')) and I want to save the content of these statements in a textfile. The problem is, that there are several different types of t...

How can I restrict find to only search specific sub-directories?

I am using find in a Bash script. How can I modify that code to include a specific directory under 'bin' , ie './bin/php/' (while still ignoring all other sub-directories of 'bin')? Current code: find . -name '*.php' \ -and ! -path './bin/*' \ ...

Removing duplicates on a variable without sorting.

I have a variable that contains the following space separated entries. variable="apple lemon papaya avocado lemon grapes papaya apple avocado mango banana" How do I remove the duplicates without sorting? #Something like this. new_variable="apple lemon papaya avocado grapes mango banana" I have found somewhere a script that accompli...

bash script doesnt run correctly as background process

I have bash script which works well but when I send it back with nohup script & and close my terminal session then it's not working correctly. It only works well within my terminal session open. What could be possible reasons which affects my script run not correctly without my terminal session? Could it be one of the terminal variabl...

What does "$$" means in shell script?

I came across "$$" expression in shell script, something like this TFILE=$$ Can anyone tell me its meaning? ...

Bash Scripting General Questions (conditionals and variable passing)

I'm rather new to bash scripting, and Google isn't as useful as I'd like for this. I'm just playing around with a little password entry program in my .bash_profile and have something like this: read PASSWORD if $PASSWORD != 'pass'; then echo "wrong. exiting" exit fi Unfortunately, this doesn't work. I get these errors (darwin...

how to Enter data from keyboard in shell programming

how to Enter data from keyboard in shell programming ? some command similar to scanf in c ...

Difference between launching a script with ./script.sh and . ./script.sh

Please tell me what is the difference in bash shell between launching a script with ./script.sh and . ./script.sh? ...

Easiest way to extract the urls from an html page using sed or awk only.

I want to extract the URL from within the anchor tags of an html file. This needs to be done in BASH using SED/AWK. No perl please. What is the easiest way to do this? Thanks a lot. ...

How do I prompt a user for confirmation in bash script?

I want to put a quick "are you sure?" prompt for confirmation at the top of a potentially dangerous bash script, what's the easiest/best way to do this? ...

A simple small shell script to compute averages

Can anyone tell me what I'm doing wrong here? #!/bin/sh if [ $# = 0 ] then echo "Usage: $0 <filename>" exit 1 fi sum=0 count=0 while [ $0 != 0 ] do sum="$sum"+"$2" count="$count"+ 1 done if [ "$count" != 0 ] then avg="$sum"/"$count" printf "Sum= $sum \n Count= $count \n Avg= $avg" exi...

What is wrong in this code

Here i have got various inputs from keyboard and checked these validations Book_id must be unique. Subject code can only be either UNIX or C.The Shelll i work is bash i got the following errors ./test.sh: line 5: declare: `=0': not a valid identifier /test.sh: line 13: unix: command not found ./test.sh: line 92: syntax error: un...

Bash Script on a Mac creates a info popup

Is there a way in bash on a mac to draw a pretty info box that displays a simple message like "please save all files to /Users/......" ...

Pick Up curent user in bash on a mac when running as a login hook

My Script currently takes the first user returned from "users" and in testing it worked fine but once i turned it into a login hook it couldn't pickup the user properly. Is there a way to pickup the user that is logging in? Using $USER doesnt work either Ive tried using "/usr/bin/logname" to get the username and that only returns "roo...

getting the highest subversion revision in my `R CMD build` filename

a question following making-the-subversion-revision-number-visible-in-my-r-scripts R CMD build PKG creates a file named as Package_Version.tar.gz according to the fields in DESCRIPTION. not only isn't the strictly sequential numbering coming from svn very practical here, but its $REV: number $ format does not respect the number.numb...