what i want to be is that i would like to reinvent new options that have the same functionality as
...
-u is the same functionality of conv=ucase
and -l have the same functionality as conv=lcase...
is there a way that i can put these in my script so that
whenever i will typed in command line such as
dd if=file of=file.new -u
so that the file contents will become upper case ... Please need help....
For the amount of work you need to do the return is minimal. And there is no such thing as 'adding an option' without doing a lot of coding. Also, if you use /usr/bin/dd instead of just plain dd, you will get the old behavior, not what you want.
create a script that turns -l into conv=lcase and -u into conv=lcase
#!/bin/bash
cmd="$*"
cmd= cmd=$( echo "$cmd" | sed 's/dd /\/usr\/bin\/dd /'| sed 's/\-u/conv=ucase /' | sed 's/\-l/conv=lcase /' )
eval $cmd
Be sure to add execute permissions to you new script:
chmod +x nameofnewscript
edit your login .profile or .bashrc file to create an alias for the script
alias dd=/path/to/mydd.shl
log out and then back in, your new alias will be shown in the output of:
alias
As an aside I don't see why you'd want to go to all this trouble....
Just for clarity here (there is absolutely no critical intent) - when using sed and there are a lot of escaped slashes I use a different separator - to make things easier to read.
#!/bin/bash
cmd="$*"
cmd= cmd=$( echo "$cmd" | sed 's/dd /\/usr\/bin\/dd /'| sed 's/\-u/conv=ucase /' | sed 's/\-l/conv=lcase /' )
eval $cmd
I would enter that as follows.
#!/bin/bash
cmd="$*"
cmd= cmd=$( echo "$cmd" | sed 's;dd ;/usr/bin/dd ;'| sed 's;\-u;conv=ucase ;' | sed 's;\-l;conv=lcase ;' )
eval $cmd
You can use any character that you want here, as I said just improves readability IMHO.
I would do none of the above. IMO: There is no discernable purpose (other than homework which this now appears to be) to doing any of this.
There are instances for using an alias (or a function) when for security reasons you want to do something like flip off/on ftp or sftp without breaking anything. Not because you want to spend cpu cycles so you can type "-u" instead of "conv=ucase"
Does anybody remember trigraphs in C? They came about because some early keyboards could not create certain characters. There had to be a workaround. Doing this "entry workaround" kind of thing is not inherently purposeless.
Since I cannot tell if this is homework, I'm leaving the thread open. Another mod may not do that.
i try this at home and theres a problem...
the name of my script is mydd
and i do the above like what it is said... but when i type in command line
bash@ubuntu$: dd if=mydd of=mydd.new -u
bash@ubuntu$: /path/to/mydd.sh file or directory not found