Reputation: 534
I want to create a shell script so that I can type
gc program_name.c
and achieve the same effect as if I had typed
gcc -o program_name program_name.c
Now, I know how to do this so that I can simply type gcc program_name
and get the effect:
gcc -o $1 $1.c
The problem is I want to use tab completion and this method requires me to backspace to delete the extension. (Yes, it's a picayune thing, but I'm interested in learning the general principle behind this kind of argument manipulation, too.)
In other words, I want to be able to have the script delete the trailing extension. I'm guessing I can use another variable, but I'm not sure how to say, for example, $name = $1 minus the trailing extension.
Thanks.
Upvotes: 1
Views: 509
Reputation: 1859
See whether you can take it forward from the following snippet.
pgm=test.c
echo ${pgm%%.*}
Upvotes: 0