linux 中here documents 的写法

本文介绍在Linux环境下如何使用heredocuments进行字符串操作,并通过cat命令展示其用法。

     linux中关于here documents的写法,是关于cat的用法:

     #!/bin/sh
     # we have less than 3 arguments. Print the help tesxt:
    if [ $# -lt 3 ]; then
    cat << HELP
        ren -- renames a number of files using sed regular expressions
        USAGE:
                 ren 'regexp' 'replacement' files...
        EXAMPLE:
                 rename all *.HTM files in *.html:
                 ren 'HTM$' 'html' *.HTM
  HELP
        exit 0
 fi

用 cat 命令,以<<开始,后面接HELP单词,然后以HELP结束,中间的内容就是可以显示的内容。

$ ./ren

        ren -- renames a number of files using sed regular expressions
        USAGE:
                 ren 'regexp' 'replacement' files...
        EXAMPLE:
                 rename all *.HTM files in *.html:
                 ren 'HTM$' 'html' *.HTM

$

这段代码出现以下错误,请解决: /home/wangjuncong/Documents/practice2/my_char_dev.c: In function ‘mychar_init’: ./include/linux/init.h:180:22: error: passing argument 1 of ‘class_create’ from incompatible pointer type [-Werror=incompatible-pointer-types] 180 | #define THIS_MODULE (&__this_module) | ~^~~~~~~~~~~~~~~ | | | struct module * /home/wangjuncong/Documents/practice2/my_char_dev.c:205:33: note: in expansion of macro ‘THIS_MODULE’ 205 | mychar_class = class_create(THIS_MODULE, CLASS_NAME); | ^~~~~~~~~~~ In file included from ./include/linux/device.h:31, from /home/wangjuncong/Documents/practice2/my_char_dev.c:148: ./include/linux/device/class.h:228:54: note: expected ‘const char *’ but argument is of type ‘struct module *’ 228 | struct class * __must_check class_create(const char *name); | ~~~~~~~~~~~~^~~~ /home/wangjuncong/Documents/practice2/my_char_dev.c:205:20: error: too many arguments to function ‘class_create’ 205 | mychar_class = class_create(THIS_MODULE, CLASS_NAME); | ^~~~~~~~~~~~ In file included from ./include/linux/device.h:31, from /home/wangjuncong/Documents/practice2/my_char_dev.c:148: ./include/linux/device/class.h:228:29: note: declared here 228 | struct class * __must_check class_create(const char *name); | ^~~~~~~~~~~~ cc1: some warnings being treated as errors make[3]: *** [scripts/Makefile.build:244: /home/wangjuncong/Documents/practice2/my_char_dev.o] Error 1 make[2]: *** [/home/wangjuncong/Documents/practice2/linux-6.9/Makefile:1919: /home/wangjuncong/Documents/practice2] Error 2 make[1]: *** [Makefile:240: __sub-make] Error 2 make[1]: Leaving directory '/home/wangjuncong/Documents/practice2/linux-6.9' make: *** [Makefile:4: all] Error 2
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值