scripting

Csh adding strings to an array, whitespace troubles

孤者浪人 提交于 2019-12-18 04:54:15
问题 I’m having trouble doing something basic with csh. I have a string: set newCmd = "$expansionCmd –option1 –option2 …" And I’m creating an array of these strings, which I later want to execute: set expansionCmdList = ($expansionCmdList[*] "$newCmd") #I also tried without quotes, e.g. just $newCmd Finally I try to iterate over and execute these commands: foreach exCmd ($expansionCmdList) `exCmd` #execute it in the shell end However the problem is that the array entries are not the full string,

Is it good style to call bash commands within a Python script using os.system(“bash code”)? [closed]

南笙酒味 提交于 2019-12-18 04:14:52
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well. I know how to implement some of the functionality I need in Bash and in Python, but it

Apply regular expression substitution globally to many files with a script

笑着哭i 提交于 2019-12-18 04:13:07
问题 I want to apply a certain regular expression substitution globally to about 40 Javascript files in and under a directory. I'm a vim user, but doing this by hand can be tedious and error-prone, so I'd like to automate it with a script. I tried sed, but handling more than one line at a time is awkward, especially if there is no limit to how many lines the pattern might match. I also tried this script (on a single file, for testing): ex $1 <<EOF gs/,\(\_\s*[\]})]\)/\1/ EOF The pattern will

SQL Scripts - Does the equivalent of a #define exist?

穿精又带淫゛_ 提交于 2019-12-18 03:41:18
问题 I have a script that I use to construct both the tables and stored procedures. For example I have a column of type varchar . varchar requires a size parameter, that size I also use as parameters in stored procedures and within those procedures. is it possible to have thequivalentnt of a #define for its size, so I can easily adjust the size without the necessity of having to change ithroughht the whole of the script? I am using MySql workbench. EDIT I have tried SET and DECLARE I have a script

Passing arguments to a command in Bash script with spaces

随声附和 提交于 2019-12-18 03:31:06
问题 I'm trying to pass 2 arguments to a command and each argument contains spaces, I've tried escaping the spaces in the args, I've tried wrapping in single quotes, I've tried escaping \" but nothing will work. Here's a simple example. #!/bin/bash -xv ARG="/tmp/a b/1.txt" ARG2="/tmp/a b/2.txt" ARG_BOTH="\"$ARG\" \"$ARG2\"" cat $ARG_BOTH I'm getting the following when it runs: ARG_BOTH="$ARG $ARG2" + ARG_BOTH='/tmp/a\ b/1.txt /tmp/a\ b/2.txt' cat $ARG_BOTH + cat '/tmp/a\' b/1.txt '/tmp/a\' b/2.txt

How to remove System.out.println's from codebase

北战南征 提交于 2019-12-18 02:48:14
问题 We have a huge (old legacy java) code-base, where many files (around 5k) have System.out.println's. We are planning to remove them for cleanup/performance reasons. How can we write a script that will replace them without introducing any issues in the code? The script cannot blindly delete them as following case can be an issue: if () some.code... else System.out.println(...); DB.close(); I'm thinking of replacing them with ';'. That will take care of above case. Do you see any other issues?

Why doesn't my variable seem to increment in my bash while loop?

这一生的挚爱 提交于 2019-12-18 02:29:05
问题 I am fairly new to bash scripting. I can't seem to get the correct value of my counting variables to display at the end of of a while loop in my bash script. Background: I have a fairly simple task: I would like to pass a text file containing a list of file paths to a bash script, have it check for the existence of those files, and count the number of existing/missing files. I got most of the script to work, except for the counting part. N=0 correct=0 incorrect=0 cat $1 | while read filename

What would be the simplest way to daemonize a python script in Linux?

天涯浪子 提交于 2019-12-18 01:14:09
问题 What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. 回答1: See Stevens and also this lengthy thread on activestate which I found personally to be both mostly incorrect and much to verbose, and I came up with this: from os import fork, setsid, umask, dup2 from sys import stdin, stdout, stderr if fork(): exit(0) umask(0) setsid() if fork(): exit(0) stdout.flush() stderr.flush() si =

Automate import of Java (Android) projects into Eclipse workspace through commandline

亡梦爱人 提交于 2019-12-17 23:12:49
问题 I'm trying to automate importing projects to an Eclipse workspace via commandline (using a bash script). I have seen many posts suggesting using the CDT headless build even for non-C/C++ projects, but I want to avoid having to download CDT as my projects are all Java/Android projects and I want to be able to automate this for many people without having to make them all download CDT. I have tried the following with the JDT headless build with no avail: eclipse -nosplash \ -application org

How to read plist information (bundle id) from a shell script

爷,独闯天下 提交于 2019-12-17 22:45:38
问题 I'd like to write a script that can read info like Bundle Identifier or maybe version number from the Info.plist of the app. Xcode doesn't seem to give that information in it's environment variables. Is there any other way to get them in sh/bash? 回答1: The defaults command can read/write to any plist file, just give it a path minus the .plist extension: $ defaults read /Applications/Preview.app/Contents/Info CFBundleIdentifier com.apple.Preview This pulls the CFBundleIdentifier value directly