Sponsored Content
Operating Systems OS X (Apple) A simple reminder script for beginners to shell scripting. Post 302890207 by Scrutinizer on Tuesday 25th of February 2014 04:58:08 PM
Old 02-25-2014
Hi Wisecracker, nice idea for a script..

Here are a couple of remarks, so it could be improved further:

1. The shebang is #!/bin/sh, so the script should conform to Posix Shell Standards and not use bash code..

2.:
Code:
if [ "$1" == "" ] || [ "$2" == "" ]

should be
Code:
if [ "$1" = "" ] || [ "$2" = "" ]

3.
Code:
str_len=`printf "${#countdown}"`

Can be written as:
Code:
str_len=${#countdown}

4.
Code:
str_len=$[ ( $str_len - 1 ) ]

$[ ... ] is deprecated bash code. It should be:
Code:
str_len=$(( str_len - 1 ))

5.
Code:
for n in $( seq 0 1 $str_len )

should be:
Code:
n=0
while [ $n -le $str_len ]; 
do
  ...
  n=$((n+1))
done

6.
Code:
number=`printf "${countdown:$n:1}"`

could be written as number=${countdown:$n:1}, but would still be bash code.
Consider using ${var%"${var#?}"} for example and vary the number of question marks...
Another option would be to replace the for loop with a case statement
Code:
case $countdown in 
  (*[!0-9]*) countdown=30
esac

7.
Code:
echo "printf '\033[1m\033[12;3f$text\033[0m\n\n\n'"

For security and other reasons it is best to not use the format field for uncontrolled data. So perhaps something like:
Code:
echo "printf '\033[1m\033[12;3f%s\033[0m\n\n\n' \"$text\""

8. There should be a wait statement after the last done
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

need a simple shell script

Hi, I am new to unix as well as shell programming. Any body can provide me a simple shell script which should copy/transfer/fetch a file(using FTP)from remote server to local system.and it should log the details when it was fetched.If there is any error,the error msg should log in log... (1 Reply)
Discussion started by: Mar1006
1 Replies

2. UNIX for Advanced & Expert Users

I need of a simple shell script

Hi, I need of a simple shell script to launch a perl script. The complet path of the script is: /export/home/x2693/project/v02/appliancemanagement.pl (2 Replies)
Discussion started by: Minguccio75
2 Replies

3. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

4. Shell Programming and Scripting

using XML::simple in shell scripting

CPAN provide xml::simple module which can be used to generate XML files. can i use this module in shell scripting? how? plzz give me an example to generate xml file using this module . you can also use some other module.. BUT SHELL SCRIPTING SHOULD ONLY BE USED (4 Replies)
Discussion started by: cynosure2009
4 Replies

5. Shell Programming and Scripting

Simple Shell Script

Hello Friends, I am writing a shell script which will grab a file if it exists and copies it to another folder and will append with current date. I have written but gives me error, plz help: -------------------------------------------- #!/usr/bin/sh source=/home/dev4rice/naveen/test1... (4 Replies)
Discussion started by: ganesh123
4 Replies

6. Shell Programming and Scripting

Help :: Simple Shell Scripting

Hello, I want to find the "IP-OF-SERVER" in /etc/squid/squid.conf And replace it with The IP of server. I know this command returns the IP of server : ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' And I can replace with sed. : sed -i... (4 Replies)
Discussion started by: Ghadamyari
4 Replies

7. Shell Programming and Scripting

Shell program for beginners

Hey, i hope someone can help me with this program. I need to write a program in shell which will return how many times and how much time have users been logged in system between two dates. We give time as 2 dates as arguments in command line. Example: $ nameofprogram 27/04 06/05 ... (1 Reply)
Discussion started by: Exander
1 Replies

8. Homework & Coursework Questions

Simple Shell Scripting

1. The problem statement, all variables and given/known data: An argument example: ../path/cse/lab3/remove Right now, it's printing out all the directory and files in 'lab3'. I want it to print out all the files in 'remove'. I'm not sure how to do that. (I want to use a for loop) 2.... (2 Replies)
Discussion started by: spider-man
2 Replies

9. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

10. Shell Programming and Scripting

Need Help on simple script as i dont know numch about UNIX scripting

Hello All, My name is vasu and I am very new to Unix scripting, i know basic commands, but now i need to write the following script, i have tried but no luck My requirment is i am getting one our from another command as following Used:1.8TB Advisory Quota:1.8TB aaa1 Used:4.5TB Advisory... (1 Reply)
Discussion started by: VasuKukkapalli
1 Replies
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy