shell

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

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

“let” internal shell command doesn't work in a shell script?

99封情书 提交于 2021-02-08 12:56:34
问题 I did a=1234 let "a=a+1" on command line and it's fine. But when I do the same in a shell script. It prints out an error that "let: not found". Here is the script file. #!/bin/sh a=1234; let "a=a+1"; echo "$a"; Thanks, 回答1: The problem is likely that /bin/sh is not the same as, or does not behave the same as, your normal shell. For example, when bash is invoked as /bin/sh , it provides a subset of its normal features. So, you may need to change your shebang line to use a different shell: #!

how to use shell variable in expect session?

你。 提交于 2021-02-08 11:57:29
问题 I try so send some files toward multiple servers using scp in bash script. But I encountering problem. here is the shell script I wrote. #!/bin/sh IP_LIST=('127.0.0.x' '127.0.0.y' '127.0.0.z') for ip_addr in "${IP_LIST[@]}" do echo "$ip_addr" expect << 'EOS' set timeout 10 spawn scp -p /home/foo/bar/baz.txt user@"$ip_addr":/home/destdir expect "*password*" send "pasword\r" expect eos exit 0 EOS done I assume each element in ip_addr is assigned to the variable ip_addr , but in expect session,

how to use shell variable in expect session?

假如想象 提交于 2021-02-08 11:57:21
问题 I try so send some files toward multiple servers using scp in bash script. But I encountering problem. here is the shell script I wrote. #!/bin/sh IP_LIST=('127.0.0.x' '127.0.0.y' '127.0.0.z') for ip_addr in "${IP_LIST[@]}" do echo "$ip_addr" expect << 'EOS' set timeout 10 spawn scp -p /home/foo/bar/baz.txt user@"$ip_addr":/home/destdir expect "*password*" send "pasword\r" expect eos exit 0 EOS done I assume each element in ip_addr is assigned to the variable ip_addr , but in expect session,

Is it possible to use xdotool to enter a web console command?

怎甘沉沦 提交于 2021-02-08 11:56:49
问题 Is it possible to use xdotool to enter a web console command like this command: $("#var2").css("move", - 44 + "deg") 回答1: Yes is possible, you can use web console or address bar. with this step: Focus on Browser press F12 Type code this example xdotool script using web console: search --sync --onlyvisible --name "chrome" windowactivate --sync keydown F12 sleep 1 type --clearmodifiers --delay 10 --args 1 "document.getElementsByTagName('body')[0].style.backgroundColor = 'green'" sleep 1 key

Python: Subprocess “call” function can't find path

[亡魂溺海] 提交于 2021-02-08 11:31:25
问题 I have a python program that needs to run a bash command on a server. The program works when I run a bash command in my local directory like this: import subprocess from subprocess import call call(['bash', 'Script_Test.sh']) However, after SSH'ing to a server and running a similar line of code below with a path on the server to a bash script, I get the error "No such file or directory" call['bash', path] This doesn't make sense for a number of reasons. I triple checked that the path is

What terminal command can I use to terminate the cursor/mouse process on a MacOSX?

左心房为你撑大大i 提交于 2021-02-08 11:13:12
问题 What terminal command can I use to terminate the cursor/mouse process on a MacOSX? I'm changing the size of the mouse using another command in the terminal and now I need to restart the process that displays the cursor. I have searched for hours for a similar topic, but couldn't find one. Does anybody know how to achieve this? 回答1: If by "changing the size of the mouse using another command in the terminal", you mean that you set the System Preferences value (i.e. using 'defaults' command),

source bashrc doesn't work in cron

北战南征 提交于 2021-02-08 10:30:54
问题 All we know that cron ignores variables defined in “.bashrc” and “.bash_profile”, so we have to define it inside cron. I constantly do the same what was written inside the similar question https://unix.stackexchange.com/questions/67940/cron-ignores-variables-defined-in-bashrc-and-bash-profile but still global variables inside .bashrc still not working. I found way to execute it - by defining sh script with "set +a" bashrc script. But "source" still doesn't work. SHELL=/bin/bash BASH_ENV=/root

Escaping double quotation marks in sed

依然范特西╮ 提交于 2021-02-08 10:28:24
问题 Creating a search and replace function for my application, I am running a test scenario with 3 files, array tscript test I am trying to escape double quotation marks but it wont work script file contains variableName=$1 sed "s#data\-field\=\"${variableName}\.name\"#data\-field\=${variableName}\.name data\-type\=dropdown data\-dropdown\-type\=${variableName}#g" test test file contains data-field=“fee_category.name” data-field=“tax_type.name” array file contains fee_category tax_type There is