scripting

My Bash aliases don't work

大兔子大兔子 提交于 2019-12-21 04:23:10
问题 I'm not sure why but my Bash aliases don't seem to work. Here is my .bashrc file # v 0.0.1 - 7/03/12 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting # expanding history to 10000 commands export HISTSIZE=10000 # don't store repeated commands more than once export HISCONTROL=ignoredups # where to look for Java export JAVA_HOME=/Library/Java/Home # tomcat server

Interesting usage of tar… but what is happening?

不问归期 提交于 2019-12-21 04:13:15
问题 I saw the following interesting usage of tar in a co-worker's Bash scripts: `tar cf - * | (cd <dest> ; tar xf - )` Apparently it works much like rsync -av does, but faster. The question arises, how? -m EDIT : Can anyone explain why should this solution be preferable over the following? cp -rfp * dest Is the former faster? 回答1: On the difference between cp and tar to copy the directory hierarchies, a simple experiment can be conducted to show the difference: alastair box:~/hack/cptest [1134]%

Grep Recursive and Count

老子叫甜甜 提交于 2019-12-21 03:52:48
问题 Need to search a directories with lots of sub-directories for a string inside files: I'm using: grep -c -r "string here" * How can I total count of finds? How can I output to file only those files with at least one instance? 回答1: It works for me (it gets the total number of 'string here' found in each file). However, it does not display the total for ALL files searched. Here is how you can get it: grep -c -r 'string' file > out && \ awk -F : '{total += $2} END { print "Total:", total }' out

Shorter Scala Script header

北慕城南 提交于 2019-12-21 00:12:14
问题 It's possible to write shell scripts in Scala by starting a text file with: #!/bin/sh exec scala "$0" "$@" !# To ease script creation, I would like to write an executable called scalash (perhaps a BASH script) allowing to shorten Scala script header to just one line: #!/bin/scalash Is it possible ? Extra points if I can pass optional parameters to scalash , for instance to add classpath dependencies. 回答1: In Scala 2.11, you can do it as follows (exactly as with most other languages): #!/usr

How can I let users run a script with root permissions?

人走茶凉 提交于 2019-12-20 23:56:12
问题 Given the dangers of SUID shell scripts, is there a more secure way of giving passwordless access to scripts (bash, PHP) with root permissions in Linux? (Ubuntu 8.10) 回答1: You could consider sudo. Although not 'passwordless', it doesn't require the user to be given the root password. It can also provide an audit trail of use of the script. edit: as per comment from Chris, there is an option not to require a password at all for certain commands, see here for details. It can also be set up not

Scripting with Scala: How to launch an uncompiled script?

天涯浪子 提交于 2019-12-20 12:42:49
问题 Apart from serious performance problems, Scala is a very powerful language. Therefore I am now using it frequently for scripted tasks inside Bash. Is there a way to just execute a *.scala file exactly the way I can do with Python files? As far as I know, Python uses bytecode to execute programs, exactly like the JVM does. However, there is not anything called pythonc (like scalac or javac) I need to call in order to accomplish this. Hence I expect Scala to be able to act in a similar manner.

Ruby escape ARGV argument or string as argument to shell command

你。 提交于 2019-12-20 11:11:02
问题 Ok this is driving me crazy: `ls #{"/media/music/Miles Davis"}` fails because of the space between "Miles" and "Davis" Say I write a ruby script and a user passes file path as an argument. How do I escape it and feed to a shell-out command. Yes, yes, I know, shelling out should be avoided. But this is a contrived example, I still need this. I would do system("ls", ARGV[0]) , but it doesn't return the stdout output of ls as a string, which is what backticks do well. How do escape whatever you

What is the difference between spawn and exec?

风格不统一 提交于 2019-12-20 10:37:53
问题 I'm learning to write a TCL (expect) scripts and I notice that some examples show to use spawn, while others show the command exec. I tried googling, but can't find what is the difference? Suppose I call 'exec' in a middle of a long expect script, what can I expect to happen? 回答1: spawn is an expect command not a tcl command. exec is a tcl command. spawn creates a process. The processes' input and output are connected to expect for use by the other expect commands: send , expect and interact

Shell loops using non-integers?

烂漫一生 提交于 2019-12-20 10:33:39
问题 I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers: #!/bin/bash for (( i=10; i<=100000; i+=100)) do ./hw3_2_2 $i done The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers? 回答1: I find it surprising that in five years no one ever mentioned the utility created just for

Calling a python function from bash script

邮差的信 提交于 2019-12-20 10:27:39
问题 I have an "alarm email" function inside a python module. I want to be able to call this function from a bash script. I know you can call a module using 'python ' in the script, but I'm not if you can or how you would call a specific function within the module. 回答1: python -c'import themodule; themodule.thefunction("boo!")' 回答2: You can use the -c option: python -c "import random; print random.uniform(0, 1)" Modify as you need. 回答3: To call a specific function in a module, assure that the