0

Hi,
I am trying to write a code in which i want to read the command line arguement ( which i can get by using $(0,1,...) ) and want to give the arguement to some filename.

Eg. ./myprogram filename.cpp

I want to remove ".cpp" from the filename and want to save only "filename" in separate variable, lets say $FIRSTARGV.

echo $1
$FILEARGV = ??
echo $FILEARGV // expected "filename"

./myprogram filename.cpp

output:-
filename

Thanks
Umesh

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Watael
1

hi,

shell variable replacements can do this

$ var="filename.cpp" #note there are no spaces around the equal sign
$ echo "${var%.*}" #always quote variable replacements
filename

see your shell's man page

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.