bash – ‘printf -v’有什么作用?

前端之家收集整理的这篇文章主要介绍了bash – ‘printf -v’有什么作用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在网上的bash脚本示例中遇到过几次这个printf -v之后,以及有关stackoverflow的几个问题,我在printf联机帮助页中找不到合适的解释.

男人printf或男人3 printf不帮助我.

我在哪里寻找?

linux中存在几个printf命令:

> printf作为已知的C函数. (在man 3 printf中描述)
> GNU printf,位于/usr/bin/printf中. (见man printf)
> bash的printf内置. (参见man bash并在SHELL BUILTIN COMMANDS部分查看条目).也可以通过help printf找到帮助,它将显示联机帮助页中的内置说明.

要找出您确切需要的内容,请使用type< command>找出特别使用的东西:

  1. root@pi:~# type printf
  2. printf is a shell builtin

所以3号是这里的解决方案:

printf [-v var] format [arguments]

-v选项使输出分配给变量var而不是打印到标准输出.

摘录自此处:

  1. printf [-v var] format [arguments]
  2. Write the formatted arguments to the standard output under the control
  3. of the format. The -v option causes the output to be assigned to the
  4. variable var rather than being printed to the standard output.
  5.  
  6. The format is a character string which contains three types of objects:
  7. plain characters,which are simply copied to standard output,character
  8. escape sequences,which are converted and copied to the standard
  9. output,and format specifications,each of which causes printing
  10. of the next successive argument. In addition to the standard printf(1)
  11. format specifications,printf interprets the following extensions:
  12.  
  13. %b causes printf to expand backslash escape sequences in the
  14. corresponding argument (except that \c terminates output,backslashes in \',\",and \? are not removed,and octal escapes
  15. beginning with \0 may contain up to four digits).
  16.  
  17. %q causes printf to output the corresponding argument in a format that
  18. can be reused as shell input.
  19.  
  20. %(datefmt)T
  21. causes printf to output the date-time string resulting from using
  22. datefmt as a format string for strftime(3). The corresponding
  23. argument is an integer representing the number of seconds since
  24. the epoch.
  25.  
  26. Two special argument values may be used:
  27.  
  28. -1 represents the current time,and
  29. -2 represents the time the shell was invoked.
  30.  
  31. Arguments to non-string format specifiers are treated as
  32. C constants,except that a leading plus or minus sign is allowed,and if the leading character is a single or double quote,the value is the ASCII value of the following character.
  33.  
  34. The format is reused as necessary to consume all of the arguments.
  35. If the format requires more arguments than are supplied,the extra
  36. format specifications behave as if a zero value or null string,as appropriate,had been supplied.
  37.  
  38. The return value is zero on success,non-zero on failure.

猜你在找的Bash相关文章