Why is line 17 not working (commented in code)?:

#!/bin/nawk -f

BEGIN {
    print "<html>"
    print "<body>"
    print "  <table border=2>"
    print "    <tr>"
    print "      <th>Name</th>"              
    print "      <th>Username</th>"              
    print "      <th>Email</th>"                    
    print "    </tr>"
}

{
    print "    <tr>"
    print "      <td>" $2 " " $1"</td>"                   
    print "      <td>"'{Substr($1,1,1)}' "</td>"  ###### Line 17                 
is
    print "      <td>" $3 "</td>"             

Am I allowed to put a statement like that in line 17? Im trying to get the first letter of the first name.

有帮助吗?

解决方案

The single quotes in this line should be removed. Currently the quoting allows the shell to parse Substr and you do not want that to happen.

Also the command is substr not Substr.

print "      <td>"'{Substr($1,1,1)}' "</td>"  ###### Line 17      

change to-:

print "      <td>" substr($1,1,1) "</td>"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top