bash

How to generate 10 million random strings in bash

廉价感情. 提交于 2021-02-08 12:07:06
问题 I need to make a big test file for a sorting algorithm. For that I need to generate 10 million random strings. How do I do that? I tried using cat on /dev/urandom but it keeps going for minutes and when I look in the file, there are only around 8 pages of strings. How do I generate 10 million strings in bash? Strings should be 10 characters long. 回答1: This will not guarantee uniquness, but gives you 10 million random lines in a file. Not too fast, but ran in under 30 sec on my machine: cat

Using variable value as variable name in bash

試著忘記壹切 提交于 2021-02-08 11:59:36
问题 I've seen this question asked before but I can't seem to get the grasp of it. I have this variable that I get from user input read column_number and then I join it with the "col" prefix to form the name of my variable selected_column="col"$column_number But when I try to evaluate it to get the result, I keep getting the (standard_in) 1: syntax error sum=$(round $sum+"echo ${!selected_column}", 2) full code: 回答1: column_number=5 selected_column=col$column_number col5=42 sum=17 echo $(($sum+${

Check domain availability — avoiding front running — using wildcards or regex

我是研究僧i 提交于 2021-02-08 11:58:27
问题 I can check for the availability of a an individual domain via whois abc123.com . I can't figure out how to check the availability of a whole set of domains that match criteria , like XXX YYY . Z . where X is any 3 of the same letters, Y is any 3 of the same numbers, and Z is any of com, org, or io. Like aaa111.org That's just an example case, but you get the idea - I'd like to specify strings, patterns, and endings, and see what's available. I can do this kind of string matching with Regex,

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,

Associate a shell script (starting a Java JAR) with a file extension in a Mac application bundle

北慕城南 提交于 2021-02-08 11:48:42
问题 To run a Java8-JAR archive on Macs with a higher Java version I pack the jar into an APP bundle (stuff.app) together with a bash-script, let's call it stuff.sh (edit: removed "-cp" argument, inserted echoing command line arguments): #!/bin/bash VM_ARGS_A="--add-modules=java.xml.bind" # Set the working directory DIR=$(cd "$(dirname "$0")"; pwd) APP_JAR="some-java-stuff.jar" APP_NAME="Some Java Stuff" APP_ICNS="stuff.icns" #test: set command line args STUFF_TITLE="Launching $APP_NAME" STUFF

Associate a shell script (starting a Java JAR) with a file extension in a Mac application bundle

荒凉一梦 提交于 2021-02-08 11:48:04
问题 To run a Java8-JAR archive on Macs with a higher Java version I pack the jar into an APP bundle (stuff.app) together with a bash-script, let's call it stuff.sh (edit: removed "-cp" argument, inserted echoing command line arguments): #!/bin/bash VM_ARGS_A="--add-modules=java.xml.bind" # Set the working directory DIR=$(cd "$(dirname "$0")"; pwd) APP_JAR="some-java-stuff.jar" APP_NAME="Some Java Stuff" APP_ICNS="stuff.icns" #test: set command line args STUFF_TITLE="Launching $APP_NAME" STUFF

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

Redirect stdout and stderr to different program without changing exit code

被刻印的时光 ゝ 提交于 2021-02-08 11:15:09
问题 This post basically asks the same question but I want an additional requirement, which is: the exit code should be unchanged. The accepted answer uses pipe, so the exit code is no longer the exit code of command1 . Command set pipefail doesn't fit my need as I don't want to affect the behavior when executing command1 , which might be a compound Bash command itself. I tried the following approach, but the output is not as expected: [hidden]$ (echo haha; echo hehe 1>&2) > >(while read -r x; do

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),