Linux command
erb 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Process ERB template
erb [template.erb]
Process with Ruby variables
erb -r [./vars.rb] [template.erb]
Output to file
erb [template.erb] > [output.html]
Trim mode for cleaner output
erb -T - [template.erb]
Print result without newline
erb -P [template.erb]
说明
erb processes ERB (Embedded Ruby) templates, allowing Ruby code to be embedded within text files. ERB is commonly used in Rails views and configuration file generation. Templates use special tags: `<%= expr %>` outputs the expression result, `<% code %>` executes code without output, and `<%# comment %>` is for comments.
参数
- -r _library_
- Require Ruby library before processing.
- -T _mode_
- Trim mode: 0, 1, 2, or -.
- -P
- Don't print newline after output.
- -e
- Ignore RUBYOPT environment variable.
- -x
- Print Ruby script instead of executing.
- -n
- Print line numbers in output.
- -v
- Verbose mode.
- --version
- Show version.
FAQ
What is the erb command used for?
erb processes ERB (Embedded Ruby) templates, allowing Ruby code to be embedded within text files. ERB is commonly used in Rails views and configuration file generation. Templates use special tags: `<%= expr %>` outputs the expression result, `<% code %>` executes code without output, and `<%# comment %>` is for comments.
How do I run a basic erb example?
Run `erb [template.erb]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -r _library_ do in erb?
Require Ruby library before processing.