bash

Compress heredoc declaration to one line in bash?

邮差的信 提交于 2021-02-08 17:01:05
问题 I have this which works to declare a JSON string in a bash script: local my_var="foobar" local json=`cat <<EOF {"quicklock":"${my_var}"} EOF` The above heredoc works, but I can't seem to format it any other way, it literally has to look exactly like that lol. Is there any way to get the command to be on one line, something like this: local json=`cat <<EOF{"quicklock":"${my_var}"}EOF` that would be so much nicer, but doesn't seem to take, obviously simply because that's not how EOF works I

Why does ((0)) cause a Bash script to exit if `set -e` directive is present?

为君一笑 提交于 2021-02-08 16:59:39
问题 This outputs before\n : #!/usr/bin/env bash set -e echo before ((0)) echo after Removing set -e or changing ((0)) to ((1)) makes the program output before\nafter\n as expected. Why does ((0)) trigger the set -e exit condition? 回答1: This will explain: ((0)) echo $? 1 ((1)) echo $? 0 So it is due to non-zero return status of arithmetic expression evaluation in (( and )) your script is exiting when set -e is being used. As help set says this: -e Exit immediately if a command exits with a non

Why does ((0)) cause a Bash script to exit if `set -e` directive is present?

混江龙づ霸主 提交于 2021-02-08 16:59:10
问题 This outputs before\n : #!/usr/bin/env bash set -e echo before ((0)) echo after Removing set -e or changing ((0)) to ((1)) makes the program output before\nafter\n as expected. Why does ((0)) trigger the set -e exit condition? 回答1: This will explain: ((0)) echo $? 1 ((1)) echo $? 0 So it is due to non-zero return status of arithmetic expression evaluation in (( and )) your script is exiting when set -e is being used. As help set says this: -e Exit immediately if a command exits with a non

Echo -n With String argument printing the “-n” part, even though not within quotation marks

橙三吉。 提交于 2021-02-08 16:42:16
问题 I've been learning how to script in bash, but I'm coming across a frustrating bug. In the below code, which just runs to print 10 rows and ten with ten columns, whenever the echo -n "$j " runs, the output prints out both a new line and the "-n" argument to the echo command. The echo command and the echo -n both work perfectly fine on their own, but for some reason, don't work within this script... Thank you in advance #Nested for loop for i in 1 2 3 4 5 6 7 8 9 10 do echo -n "Row $i: " for j

Echo -n With String argument printing the “-n” part, even though not within quotation marks

拈花ヽ惹草 提交于 2021-02-08 16:41:37
问题 I've been learning how to script in bash, but I'm coming across a frustrating bug. In the below code, which just runs to print 10 rows and ten with ten columns, whenever the echo -n "$j " runs, the output prints out both a new line and the "-n" argument to the echo command. The echo command and the echo -n both work perfectly fine on their own, but for some reason, don't work within this script... Thank you in advance #Nested for loop for i in 1 2 3 4 5 6 7 8 9 10 do echo -n "Row $i: " for j

WC command in linux

喜你入骨 提交于 2021-02-08 15:55:50
问题 The following is the content stored in my file This is my Input So, using wc -c command we can get the number of characters stored in the file. My expected output for above file that edited by using VIM in Ubuntu is 16. But, wc -c command returns 17 . Why is the output like this? There isn't even a carriage return at end of line. So, what is the 17th character? 回答1: of course you had enter. maybe you cant see it. consider these two examples: echo -n "This is my Input" | wc -c 16 because -n is

Total CPU usage - multicore system

☆樱花仙子☆ 提交于 2021-02-08 15:54:32
问题 I am using xen and with xen top I get the total CPU usage in percentage: NAME STATE CPU(sec) CPU(%) MEM(k) MEM(%) MAXMEM(k) MAXMEM(%) VCPUS NETS NETTX(k) NETRX(k) VBDS VBD_OO VBD_RD VBD_WR VBD_RSECT VBD_WSECT SSID VM1 -----r 25724 299.4 3025244 12.0 20975616 83.4 12 1 14970253 27308358 1 3 146585 92257 10835706 9976308 0 As you can see from above I see the CPU usage is 299 %, but how I can get the total CPU usage from a VM ? Top doesn't show me the total usage. 回答1: We usually see 100% cpu

Linux 软件安装 (YUM & RPM & 源码)

天涯浪子 提交于 2021-02-08 14:46:13
Liunx 中的软件安装 (详解 yum) 在win 下,安装软件 .exe 双击运行即可 Linux中,软件包封装类型多样 常见的软件包封装类型: rpm 扩展名为 .rpm deb 软件包 扩展名为 .deb 源代码软件包 一般为 .tar.gz 或者 .tar.bz2 格式的压缩包,包含程序源代码 README 提供安装程序的软件包(agent) install.sh setup .bin RPM 软件包 由 redhat 公司提出 建立统一的数据库文件,详细记录软件包安装,卸载等变化信息,能自动分析软件包依赖关系 推荐网站: http://rpmfind.net/ 软件包格式 bash-4.2-9.1.i586.rpm bash -4.2 -9.1 .i586 .rpm 软件名称 版本号 发布次数 硬件平台(noarch表示不区分硬件平台) 扩展名 YUM 源软件管理方式 YUM仓库集中化管理, 管理rpm包 很好的解决了软件包之间的依赖关系 YUM配置文件 [root[@localhost](https://my.oschina.net/u/570656) ~]# cd /etc/yum.repos.d/ # 此处为yum配置文件路径 [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]# ls

Linux 软件安装 (YUM & RPM & 源码)

喜你入骨 提交于 2021-02-08 14:19:11
Liunx 中的软件安装 (详解 yum) 在win 下,安装软件 .exe 双击运行即可 Linux中,软件包封装类型多样 常见的软件包封装类型: rpm 扩展名为 .rpm deb 软件包 扩展名为 .deb 源代码软件包 一般为 .tar.gz 或者 .tar.bz2 格式的压缩包,包含程序源代码 README 提供安装程序的软件包(agent) install.sh setup .bin RPM 软件包 由 redhat 公司提出 建立统一的数据库文件,详细记录软件包安装,卸载等变化信息,能自动分析软件包依赖关系 推荐网站: http://rpmfind.net/ 软件包格式 bash-4.2-9.1.i586.rpm bash -4.2 -9.1 .i586 .rpm 软件名称 版本号 发布次数 硬件平台(noarch表示不区分硬件平台) 扩展名 YUM 源软件管理方式 YUM仓库集中化管理, 管理rpm包 很好的解决了软件包之间的依赖关系 YUM配置文件 [root[@localhost](https://my.oschina.net/u/570656) ~]# cd /etc/yum.repos.d/ # 此处为yum配置文件路径 [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]# ls

Curious tput behavior, with stderr redirection

ε祈祈猫儿з 提交于 2021-02-08 13:50:59
问题 I'm trying to use tput in a Bash script, and doing my best to avoid random error spew. To that end, I wrote the following line: COLS="$(tput cols 2> /dev/null)" To my surprise, when I run this, COLS is consistently set to 80 , no matter what the width of my terminal window happens to be. (For the sake of demonstration, my terminal happens to be 115 columns wide.) To figure out what was going on, I tried a few things on the command-line: $ tput cols 115 $ tput cols | cat 115 $ echo "$(tput