[ncl-talk] 回复: problem about knowing the files number

LIU Chang cliucv at connect.ust.hk
Wed Dec 1 00:28:16 MST 2021


Dear Rick,

Thank you very much.

When I used the systemfunc, the problem was solved. It seems that I could use the shell language from the systemfunc in ncl script.

Million thanks again! Have a good day!

Best regards,
Chang

________________________________
发件人: Rick Brownrigg <brownrig at ucar.edu>
发送时间: 2021年11月30日 20:48
收件人: LIU Chang <cliucv at connect.ust.hk>
抄送: ncl-talk <ncl-talk at ucar.edu>
主题: Re: [ncl-talk] problem about knowing the files number

Hi,

You can use NCL's systemfunc() (http://ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml<https://apc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fncl.ucar.edu%2FDocument%2FFunctions%2FBuilt-in%2Fsystemfunc.shtml&data=04%7C01%7Ccliucv%40connect.ust.hk%7C35666a075c174bb5db5508d9b3ffb412%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C637738733089081129%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=aVl7WwnWvCQ4kVtVcsCIqHdRaaRwHH23Ce8I3lYEKQ0%3D&reserved=0>):

Something like:

   a = systemfunc("ls diri -l | grep '^-' | wc -l")

Note the use of single quotes around the grep RE. There's not a great way to escape double quotes in string literals. To do so, you need the str_get_dq() function (http://ncl.ucar.edu/Document/Functions/Built-in/str_get_dq.shtml<https://apc01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fncl.ucar.edu%2FDocument%2FFunctions%2FBuilt-in%2Fstr_get_dq.shtml&data=04%7C01%7Ccliucv%40connect.ust.hk%7C35666a075c174bb5db5508d9b3ffb412%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C637738733089091086%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Nw7FCa%2F08rbLtfnDJJrG%2Bn3KdRbNWCeR99pc0ZEsa4c%3D&reserved=0>); see the examples for usage.

Rick



On Tue, Nov 30, 2021 at 4:40 AM LIU Chang via ncl-talk <ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>> wrote:
Dear NCL,

I want to know how many files in my one dir based on NCL.

I have known that based on shell, typing  a=`ls diri -l | grep "^-" | wc -l` ​, it will echo a and a is equal to files number.
​
However, when I tried to add the sentence into my ncl script, it showed that a=`, fatal:Syntax Error in block, block not executed.

It will be really appreciated if you could give me some suggestions to solve the problem.

Best regards,
Chang LIU
_______________________________________________
ncl-talk mailing list
ncl-talk at mailman.ucar.edu<mailto:ncl-talk at mailman.ucar.edu>
List instructions, subscriber options, unsubscribe:
https://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://apc01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.ucar.edu%2Fmailman%2Flistinfo%2Fncl-talk&data=04%7C01%7Ccliucv%40connect.ust.hk%7C35666a075c174bb5db5508d9b3ffb412%7C6c1d415239d044ca88d9b8d6ddca0708%7C1%7C0%7C637738733089091086%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=0OTo1Z3oAygeh5%2BOKlN1PFnO25Dvws2W%2BomBqnamGHw%3D&reserved=0>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20211201/90f8e65a/attachment.html>


More information about the ncl-talk mailing list