Commands in all caps


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Commands in all caps
# 1  
Old 08-08-2011
Commands in all caps

Is it possible to make a bash script such that entering a command in all capital letters would be equivalent to using "sudo" before that command?

For example:
"sudo chmod 777 foo.txt" becomes "CHMOD 777 foo.txt"
# 2  
Old 08-08-2011
filenames in UNIX are case-sensitive, so doing this would rule out a lot of valid filenames.

If you only need to do this for specific commands, creating those filenames would be a straightforward way to do it:

Code:
#!/bin/sh

# filename:  /bin/CHMOD
exec sudo chmod "$@"

Or a set of functions:

Code:
function CHMOD
{
        sudo chmod "$@"
}

I don't know a way to make the shell recognize any possible all-uppercase command name just because it's uppercase. Some sort of preprocessor would probably be needed.
# 3  
Old 08-08-2011
Code:
alias CHMOD='sudo chmod'

# 4  
Old 08-08-2011
Yes, it's possible with bash. If bash didn't find a command then it execute special function "command_not_found_handle" if it exists. So you can do something like (bash 4.x):
Code:
 function command_not_found_handle { local cmd=$1; shift; sudo ${cmd,,} "$@"; }

You can use
Code:
local cmd=`echo $1 | tr 'A-Z' 'a-z'`

in an older version of bash. And of course, you may add some validation on "$cmd"
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate all possible word with caps and no caps

With use of sed/awk, how can I print all possible combinations of a word with caps/non-caps. Eg Applying operation on "cap" should generate output as follows. cap CAP Cap cAp caP CAp cAP CaP (12 Replies)
Discussion started by: anil510
12 Replies

2. UNIX for Dummies Questions & Answers

Caps lock problem

hi all this s quite a foolish problem. I seem to hav pressed some keys s.t in unix, my letters are comin in caps and with caps lock on, i am getting lowercase letters. :o Pls help. Also is there any reference or manual where i can check in case such problems arrise? thanx in advance curiosity (4 Replies)
Discussion started by: curiosity
4 Replies

3. UNIX for Dummies Questions & Answers

Is there a way to ignore CAPS or case sensitivity?

If I'm using a program that is expecting certain filenames and directories to be all CAPS, isn't there a way to ignore this in linux/cshell scripting? I.e., similiar to ignoring spaces with " (i.e., directory is directory 1, can ignore by typing "directory 1".) ?? (2 Replies)
Discussion started by: rebazon
2 Replies

4. UNIX for Dummies Questions & Answers

Copying files with caps?

Anyone know the proper command to copy files whose names CONTAIN a capital letter to a diff location? Every time I do it I ke copying ALL the files. Here is what ive tried cp ** newlocation cp newlocation (5 Replies)
Discussion started by: losingit
5 Replies

5. UNIX for Advanced & Expert Users

Set Caps and Num lock from within X?

Hello, Not sure if this is the right place to post it but.. I have a requirement to set Caps lock and/or Num lock on and off via a Cron job. Now I have working scripts that do the job, but as soon as X starts up the jobs no longer run (well they appear to, but Caps lock and Num lock do not... (0 Replies)
Discussion started by: autotuner
0 Replies

6. HP-UX

Caps lock dtterm

Hello, We are having a problem with running dtterm off a RHEL server. Logging into an HP-UX server from a RHEL 5.1 desktop, setting DISPLAY and running dtterm, the caps lock does not work. We have been playing with xmodmap & stty but to no avail. Any help appreciated. mgb (7 Replies)
Discussion started by: mgb
7 Replies

7. Red Hat

Caps lock dtterm

Hello, We are having a problem with running dtterm off a RHEL server. Logging into an HP-UX server from a RHEL 5.1 desktop, setting DISPLAY and running dtterm, the caps lock does not work. We have been playing with xmodmap & stty but to no avail. Any help appreciated. mgb (1 Reply)
Discussion started by: mgb
1 Replies

8. Shell Programming and Scripting

changing first letter to CAPS

Hi, I want to convert the first letter of this word from lowecase to uppercase. Assume a letter united. I want to translate to United Please let me know a simple way to do that. Thanks. (22 Replies)
Discussion started by: Krrishv
22 Replies
Login or Register to Ask a Question