Solved

Linux bash script to change argument to lowercase

Posted on 2011-03-07
3
475 Views
Last Modified: 2012-06-27
I have the following script which works great if the user types both arguments in all lower case.  If the user of the script types the command with any upper case letters the script will fail.  I am sure there must be a way for the user input to be proceed in all lower case.

The 2 arguments in my script are: ${CONTEXT} and  ${MACADD}

Thanks


#!/bin/bash
#
if [ -z ${2} ]
then
    echo "usage: $0 <contextname> <macaddress>"
    exit 1
fi
CONTEXT=${1}
MACADD=${2}
cat /var/softswitch/configs/device/polycom/${CONTEXT}/${MACADD}-boot.log

Open in new window

0
Comment
Question by:ipconfig610
  • 2
3 Comments
 
LVL 2

Expert Comment

by:P-Y
ID: 35059669
Try this:

#!/bin/bash
#
if [ -z ${2} ]
then
    echo "usage: $0 <contextname> <macaddress>"
    exit 1
fi
CONTEXT=${1} | tr '[A-Z]' '[a-z]'
MACADD=${2} | tr '[A-Z]' '[a-z]'
cat /var/softswitch/configs/device/polycom/${CONTEXT}/${MACADD}-boot.log
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 35059689
CONTEXT=$(echo ${1} | tr [[:upper:]] [[:lower:]])
MACADD=$(echo ${2} | tr [[:upper:]] [[:lower:]])
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35059710
Newer versions of bash also let you do this at the top of the script.  This should fix any problems you are having.

declare -l CONTEXT MACADD

Open in new window


Older versions don't understand it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question