Would you please explain why the following shell command wouldn’t work:
sh-3.1$ echo $MYPATH
/opt/Application/DATA/CROM/my_application
sh-3.1$ awk '{print substr($MYPATH,3)}'
Thanks
Best Regards
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MYPATHis not going to be substituted by the shell since the string uses single quotes. Consider the following:The usage of single quotes instructs the shell to pass the string argument to the program as-is. Double quotes tell the shell to perform variable expansion on the argument before passing it to the program. This is a basic shell feature that is common amongst shells and some programming languages (e.g., perl).
The next problem that you are going to run into is that
awkwill want quotes around the first parameter tosubstror the parse will fail. You will probably see an “Illegal variable name” warning in this case. This is where I get lost withcshsince I have no clue how to properly escape a double-quote within a quoted string. In bash/sh/ksh, you would do the following:Just in case you do not already know this,
awkwill require an input stream before it is going to do anything. I had to type “input” and the EOF character for the little example.