shell

How to execute Python inline from a bash shell

核能气质少年 提交于 2021-02-04 09:41:09
问题 Is there a Python argument to execute code from the shell without starting up an interactive interpreter or reading from a file? Something similar to: perl -e 'print "Hi"' 回答1: This works: python -c 'print("Hi")' Hi From the manual, man python : -c command Specify the command to execute (see next section). This termi- nates the option list (following options are passed as arguments to the command). 回答2: Another way is to you use bash redirection: python <<< 'print "Hi"' And this works also

History command works in a terminal, but doesn't when written as a bash script

帅比萌擦擦* 提交于 2021-02-04 06:07:00
问题 I have a simple one-liner that works perfectly in the terminal: history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head What it does: Gives out the 10 most frequently used commands by the user recently. (Don't ask me why I would want to achieve such a thing) I fire up an editor and type the same with a #!/bin/bash in the beginning: #!/bin/bash history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head And say I save it as script.sh . Then when I go to the same terminal, type

History command works in a terminal, but doesn't when written as a bash script

ε祈祈猫儿з 提交于 2021-02-04 06:04:52
问题 I have a simple one-liner that works perfectly in the terminal: history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head What it does: Gives out the 10 most frequently used commands by the user recently. (Don't ask me why I would want to achieve such a thing) I fire up an editor and type the same with a #!/bin/bash in the beginning: #!/bin/bash history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head And say I save it as script.sh . Then when I go to the same terminal, type

History command works in a terminal, but doesn't when written as a bash script

。_饼干妹妹 提交于 2021-02-04 06:04:33
问题 I have a simple one-liner that works perfectly in the terminal: history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head What it does: Gives out the 10 most frequently used commands by the user recently. (Don't ask me why I would want to achieve such a thing) I fire up an editor and type the same with a #!/bin/bash in the beginning: #!/bin/bash history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head And say I save it as script.sh . Then when I go to the same terminal, type

How to parse json response in the shell script?

给你一囗甜甜゛ 提交于 2021-02-04 04:57:13
问题 I am working with bash shell script. I need to execute an URL using shell script and then parse the json data coming from it. This is my URL - http://localhost:8080/test_beat and the responses I can get after hitting the URL will be from either these two - {"error": "error_message"} {"success": "success_message"} Below is my shell script which executes the URL using wget. #!/bin/bash DATA=$(wget -O - -q -t 1 http://localhost:8080/test_beat) #grep $DATA for error and success key Now I am not

How to parse json response in the shell script?

放肆的年华 提交于 2021-02-04 04:56:43
问题 I am working with bash shell script. I need to execute an URL using shell script and then parse the json data coming from it. This is my URL - http://localhost:8080/test_beat and the responses I can get after hitting the URL will be from either these two - {"error": "error_message"} {"success": "success_message"} Below is my shell script which executes the URL using wget. #!/bin/bash DATA=$(wget -O - -q -t 1 http://localhost:8080/test_beat) #grep $DATA for error and success key Now I am not

shell脚本实例

江枫思渺然 提交于 2021-02-03 07:20:34
1. 写一个脚本,利用循环计算10的阶乘 #!/bin/sh factorial=1 for a in `seq 1 10` do factorial=`expr $factorial \* $a` done echo "10! = $factorial" 注:上面有一行,for a in `seq 1 10`,其中seq 1 10 , 即列出现1到10之间所有的数字,这一行也可改为:for a in "1 2 3 4 5 6 7 8 9 10" 2. 写一个脚本,执行后,打印一行提示“Please input a number:",要求用户输入数值,然 后打印出该数值,然后再次要求用户输入数值。直到用户输入 "end"停止。 #!/bin/sh unset var while [ "$var" != "end" ] do echo -n "please input a number: " read var if [ "$var" = "end" ] then break fi echo "var is $var" done 3. 写一个脚本,利用循环和continue关键字,计算100以内能被3整除的数之和 #!/bin/sh sum=0 for a in `seq 1 100` do if [ `expr $a % 3` -ne 0 ] then continue fi

shell study

≡放荡痞女 提交于 2021-01-31 08:31:47
1. #!/bin/bash 2. ~/.bashrc, ~/.bash_profile 3. sh -n *.sh 测试shell脚本是否存在语法错误 4. sh -x *.sh(或者set -x) 进入跟踪方式,显示所执行的每一条命令,调试 5. set -x 开启调试, set +x 关闭调试 6. echo $? 返回值 7. echo -e 使显示的字符串中转义字符生效 8. read var / read -p "xxx" var 输入 9. myVar=${var:-"varvalue"} 变量var为空,则myVar="varvalue" 10. login shell(/etc/profile, ~/.bash_profile或~/.bash_login或~/.profile) / non-login shell(不会读配置,需要执行source生效) 11. ~/.bashrc non-login shell仅会读取.bashrc配置 12. $(), ` ` ==>在中间为子shell的起始与结束 13. ${} ==>在中间为命令区块的组合 14. ./*.sh ==>在子bash中执行shell脚本; source *.sh ==>在父bash中执行shell脚本 15. test指令; 如 test -e /usr/include/syslog.h &&

How to get the method signatures for DShellFolderViewEvents

自闭症网瘾萝莉.ら 提交于 2021-01-29 21:56:09
问题 I'm trying to sink DShellFolderViewEvents using the ATL, and the only method I've been able to successfully subscribe to is DISPID_SELECTIONCHANGED . There appear to be many other events listed in the header shdispid.h , but I can't get them to fire. Not sure what I'm doing wrong (it might be ATL-related), but I thought perhaps I'm implementing event-handler functions with the wrong signatures (currently I'm just trying void functions with no arguments). The problem is that there doesn't

Get comment tag from XML attribute with Bash

纵然是瞬间 提交于 2021-01-29 18:48:58
问题 I understand how to retrieve XML content within regular nodes, but I would like to understand how to retrieve content within a comment tag in XML using Bash. For example, consider the below XML snippet: <ParentTag1><!--This comment is associated to ParentTag1 --> <ChildTag1>ChildTag1Blah</ChildTag1><!-- ChildTag1 comment--> <ChildTag2><!-- ChildTag2 comment --> <GrandchildTag1>GrandchildTag1Blah</GrandchildTag1><!-- GrandchildTag1 comment--> <GrandchildTag2>GrandchildTag2Blah</GrandchildTag2>