shell的printf输出时包含空格问题

【Shell牛客刷题系列】SHELL21 格式化输出:来看个printf命令的小彩蛋~ 本文首先学习了printf命令地用法;然后,给出了五种题目的解决方案,涉及到了awk、sed、xargs、printf命令的用法,其次,对于本题用到的printf的一个小彩蛋也是比较有意思的。 阅读详情

printf "%-30s:%-15s\n" report_selinux_enable $report_selinux_enable

printf "%-30s:%-15s\n" report_selinux_status $report_selinux_status

printf "%-30s:%-15s\n" report_os $report_os

printf "%-30s:%-15s\n" report_hostname $report_hostname

printf "%-30s:%-15s\n" report_kernel $report_kernel

printf "%-30s:%-15s\n" report_uptime $report_uptime

printf "%-30s:%-15s\n" report_date_time $report_date_time

输出:

report_selinux_enable :disabled

report_selinux_status :Disabled

report_os :GNU/Linux

report_hostname :centos.com

report_kernel :3.10.0-693.2.2.el7.x86_64

report_uptime :42

days :

report_date_time :2018-07-18-20-24-23

可以看出输出的在线天数(report_uptime)的值是42(本来是42 days),下面还有一行显示的有问题,把一行拆成了两行显示,是因为report_uptime的值中间有空格,所以被拆成两行

解决:printf语句后面的引用值要放在""中

printf "%-30s:%-15s\n" report_uptime "$report_uptime"

printf "%-30s:%-15s\n" "report_selinux_enable" "$report_selinux_enable"

printf "%-30s:%-15s\n" "report_selinux_status" "$report_selinux_status"

printf "%-30s:%-15s\n" "report_os" "$report_os"

printf "%-30s:%-15s\n" "report_hostname" "$report_hostname"

printf "%-30s:%-15s\n" "report_kernel" "$report_kernel"

printf "%-30s:%-15s\n" "report_uptime" "$report_uptime"

printf "%-30s:%-15s\n" "report_uptime" "$report_date_time"

report_selinux_enable :disabled

report_selinux_status :Disabled

report_os :GNU/Linux

report_hostname :centos.com

report_kernel :3.10.0-693.2.2.el7.x86_64

report_uptime :42 days

report_date_time :2018-07-18-20-27-40

喜欢的点点关注,点点赞。

对Java技术,架构技术感兴趣的同学,欢迎加QQ群585550789,一起学习,相互讨论。

群内已经有小伙伴将知识体系整理好(源码,笔记,PPT,学习视频),欢迎加群领取。

Shell基础教程十: shell printf命令:格式化输出语句 printf 命令用于格式化输出, 是echo命令的增强版。它是C语言printf()库函数的一个有限的变形,并且在语法上有些不同。 注意:printf 由 POSIX 标准所定义,移植性要比 echo 好。 如同 echo 命令,printf 命令也可以输出简单的字符串: $printf "Hello, Shell\n" Hello, Shell $ printf 不像 echo 那样会自动换行,必须显式添加换行符(\n)。 printf 命令的语法: printf format-string 阅读详情

相关推荐

Shell printf 命令

我们来学习 Shell 的另一个输出命令 printf。printf 命令模仿 C 程序库(library)里的 printf() 程序。printf 由 POSIX 标准所定义,因此使用 printf 的脚本比使用 echo 移植性好。printf 使用引用文本或空格分隔的参数,外面可以在中使用格式化字符串,还可以制定字符串的宽度、左右对齐方式等。默认的 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n。

office_lgirl的博客 731

printf(“%*s“,5,““)输出多个空格简单方法

#include <stdio.h> int main(){ printf("%*s%s%*s",5,"","123",3,"" ); return 0; } 输出5个空格,输出123,输出3个空格

WonderKing'blog 4万+

Shell echo命令和Shell printf 命令

Shell echo命令和Shell printf 命令

98年热爱开发的前后端开发工程师! 606

linux shell执行时printf不显示,shell的printf输出时包含空格问题

printf "%-30s:%-15s\n" report_uptime "$report_uptime"printf "%-30s:%-15s\n" "report_selinux_enable" "$report_selinux_enable"printf "%-30s:%-15s\n" "report_selinux_status" "$report_selinux_status"print...

weixin_39853210的博客 737

FOC-滑膜控制器SMC/滑膜观测器SMO

三相PMSM是一个非线性、强耦合的多变量控制系统,对于外界的扰动或者电机自身的参数发生变化时,传统的PI控制并不能满足实际的要求。因此可以引入滑模控制SMC,它对扰动和参数不敏感,响应速度也够快。简单来说就是,滑膜观测器就是通过采样与坐标变换得到的Ualpha,Ubeta,Ialpha,Ibeta四个参数值,获取。SMO叫滑膜观测器(Sliding Mode Observer),用于获取转子位置信息与转速信息。2、作为滑膜观测器SMO,获取电机角度与转速信息。之间的误差来设计滑膜观测器,并通过该误差。

小胡同学的工程师学习之路 1万+

八路抢答器____一个作品的制作思路

学习了解到一个产品制作完全由一个人去采购,设计,仿真,画PCB。不光是需求的分析还有实现功能时如何搭建电路,和给出一个简单高效的设计方法也是至关重要的。

weixin_73690807的博客 1542

shell中printf输出

printf 命令模仿 C 程序库(library)里的 printf() 程序。 printf 由 POSIX 标准所定义,因此使用 printf 的脚本比使用 echo 移植性好。 printf 使用引用文本或空格分隔的参数,外面可以在 printf 中使用格式化字符串,还可以制定字符串的宽度、左右对齐方式等。默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n。 printf 控制格式的字符串 参数 printf "hello world\n" ...

温其如玉的博客 6468

UG/NX二次开发Siemens官方NXOPEN实例解析—1.3 BlockStyler/ExtrudewithPreview

随着工业智能化的不断发展,UG二次开发的需求越来越多,也吸引了大批的二开从业人员,本人作为一名资深IT从业者(10年+)也毅然加入二次开发大军。然而,和流行IT行业(互联网、金融、医疗等)相比,工业智能化的门槛显得更高一点,专业的工业软件,相对封闭的开发理念和更小的开发圈子,让刚进入二开的从业者有点举步维艰。边学边整理,希望通过这系列文章的整理能给二开的生态增添一叶绿。

MarcoPro的博客 1649

Shell 格式化输出printf、awk

文章目录Shell 文件的格式化与相关处理 printf、awk格式化打印printf选项与参数说明格式修饰符案例.格式化输出文件内容输出命令echo案例awk数据处理工具处理流程AWK内置变量关系表达式字段和记录分隔符变量案例1:改变输出间隔符案例2.FIELDWIDTHS的使用自定义变量数组匹配操作符~结构化命令next 跳过当前行if条件判断式循环内置函数 Shell 文件的格式化与相关处理 printf、awk 格式化打印printf 使用场景:将数据格式化输出 语法:printf ‘打印格式’ 实

好好学习天天向上 4658

Altium Designer操作技巧(4)——如何利用嘉立创EDA来输出3D封装到AD封装库?

本文介绍了利用嘉立创EDA和FreeCAD软件为PCB元件添加3D模型的方法。首先在嘉立创EDA中搜索元件编号并导出3D模型,然后使用FreeCAD删除3D模型中的PCB基板部分,最后将处理后的3D模型导入PCB封装库并更新到PCB设计中。文章详细讲解了每个步骤的操作流程,包括模型导出、基板删除、位置调整等关键环节,并提供了解决常见问题的方法。通过这种方法,电子工程师可以快速获得元器件的3D模型,提高PCB设计的准确性。

u012526819的博客 2634

RTX 50系显卡(5080/5090D)CUDA 12.8环境下的vLLM部署避坑与实战指南

本文为RTX 5080/5090D显卡用户提供了在CUDA 12.8环境下部署vLLM的完整实战指南。文章详细介绍了从驱动安装、CUDA 12.8环境配置、PyTorch Nightly版本精准匹配,到vLLM源码编译及常见报错排查的全过程,帮助开发者高效利用新一代硬件进行大模型推理。

gray5的博客 683

shell 语法:echo命令、printf命令、重定向、文件包含、函数

shell echo命令、printf命令、重定向、文件包含、函数

阿飞的博客 5134

CANape快速上手

文章帮助记录CANape学习过程。

小弱鸡的博客 1万+

Shell 输出命令echo、printf

echo Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出。命令格式: echo string 可以使用echo实现更复杂的输出格式控制。 1.显示普通字符串 echo "It is a test" 这里的双引号完全可以省略,以下命令与上面实例效果一致: echo It is a test 2.显示转义字符 echo "\"It is a test"\" 结果: "It is a test" 3.显示变量 name="hello" echo "$name wor

一条到晚游泳的鱼 2275

Apache Paimon-实时数据湖

Flink社区希望能够将 Flink 的 Streaming 实时计算能力和 Lakehouse 新架构优势进一步结合,推出新一代的 Streaming Lakehouse 技术,促进数据在数据湖上真正实时流动起来,并为用户提供实时离线一体化的开发体验。Flink 社区内部孵化了 Flink Table Store (简称 FTS )子项目,一个真正面向 Streaming 以及 Realtime的数据湖存储项目。

m0_57307642的博客 2198

通过监督微调(SFT)提升AI Agent效果的完整指南

监督微调(Supervised Fine-Tuning)是在大规模预训练语言模型(如LLaMA、GPT系列)的基础上,使用特定任务标注数据进行二次训练的过程。其本质是通过有监督学习调整模型参数,使其适应目标任务的分布特征。

保持热爱。 1942

shell脚本之printf用法

一、简介 shell脚本中的printf和C语言中的printf用法基本一致,只是在写法上有些许区别 二、基本用法 1.打印字符串 [root@algento-1 ~]# cat printf_test.sh #!/bin/bash printf "hello world" [root@algento-1 ~]# sh printf_test.sh hello world[root@algento-1 ~]# 这里发现printf默认是不带换行符号的,所以要换行需要带上\n [root@al

借风拥你 8926

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

shell的echo命令与printf有什么不同?

我们很容易知道的echo和printf的区别在于echo自带回车,而printf需要手动加\n,但是今天我发现了更深层次的区别。 今天刚开始学习shell编程。用shell可以编写sh文件,是一种可以在linux中运行的脚本。学习的地址是菜鸟教程,网址如下: https://www.runoob.com/linux/linux-shell.html 在学习for循环的时候有这样一个例子,例子的说明是“顺序输出字符串中的字符”,网址为https://www.runoob.com/linux/linux-

YNNAD1997的博客 3230

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

shell 脚本-06输出命令(echo 和 printf)

shell 脚本-echo命令 用于字符串的输出 基本输出 使用 echo string 命令输入 string 内容, 内容中的转义字符, 使用变量等规则参考字符串规则 echo "Hello World" echo "\"Hello World\"" echo 'Hello World' echo 'Hello World\"' 运行结果: Hello World “Hello World” Hello World Hello World" 使用转义 使用参数 -e 可以使 echo 命令启用转义

eno的博客 9980

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Shell printf格式化输出命令

printf 是 awk 的重要格式化输出命令,本节我们先介绍一下 printf 命令如何使用。 需要注意,在 awk 中可以识别 print 输出动作和 printf 输出动作(区别是:print 会在每个输出之后自动加入一个换行符;而 printf 是标准格式输出命令,并不会自动加入换行符,如果需要换行,则需要手工加入换行符),但是在 Bash 中只能识别标准格式化输出命令 printf。所以我们在本小节中介绍的是标准格式化输出命令 printf。 printf 命令格式如下: [root@lo...

u011250186的博客 1825
上一篇: jquery完成bootstrap动态表格
下一篇: linux下普通用户的定时任务
java1856905
博客等级 码龄8年 100粉丝 249原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址