sh

Bourne Shell For i in (seq)

巧了我就是萌 提交于 2019-11-29 03:00:50
问题 I want to write a loop in Bourne shell which iterates a specific set of numbers. Normally I would use seq : for i in `seq 1 10 15 20` #do stuff loop But seemingly on this Solaris box seq does not exist. Can anyone help by providing another solution to iterating a list of numbers? 回答1: try for i in 1 10 15 20 do echo "do something with $i" done else if you have recent Solaris, there is bash 3 at least. for example this give range from 1 to 10 and 15 to 20 for i in {1..10} {15..20} do echo "$i"

Is it necessary to quote command substitutions during variable assignment in bash?

不想你离开。 提交于 2019-11-29 02:28:14
Nearly everywhere I've read, including Google's bash scripting style guide mention to necessity of quoting command substitutions (except when specifically desired of course). I understand the when/where/why of quoting command substitutions during general use. For example: echo "$(cat <<< "* useless string *")" rather than echo $(...) However for variable assignments specifically, I have seen so many examples as such: variable="$(command)" Yet I have found no instances where variable=$(command) is not equivalent. variable="$(echo "*")" and variable=$(echo "*") both set the value to '*'. Can

How to automate creation of new XCode targets from Applescript/Automator/Shell Script

痴心易碎 提交于 2019-11-29 02:14:47
问题 I am currently working on a way to automate the process of adding new targets to my XCode projects. One target has to be added to multiple XCode projects and each target in the different project needs the same source files to be added, same groups to store the source files in the XCode project, and the same build settings. Doing this manually can take a while and is very prone to human error, and I have to do this task fairly often. I have already written a script to generate new source files

How to automatically create batch / shell scripts to run a Java console application?

瘦欲@ 提交于 2019-11-29 02:01:12
I have a Java command-line application, and would like to create an Ant* build script that will create all the required batch/shell scripts to run the application successfully including all the classpath variables. I need it to do the following: Create a shell script file for Linux/Unix and a batch file for Windows/DOS Add all classpath dependencies (from Maven or simply use the build path in Eclipse) Add any necessary boilerplate sh/bat code to run (ENV variables, JAVA_HOME, etc.) I found only a partial answer here . But I haven't found anything that does this basic and trivial task that

Get pid of current subshell

白昼怎懂夜的黑 提交于 2019-11-29 00:38:11
问题 I am trying to get the pid of a currently executing subshell - but $$ is only returning the parent pid: #!/usr/bin/sh x() { echo "I am a subshell x echo 1 and my pid is $$" } y() { echo "I am a subshell y echo 1 and my pid is $$" } echo "I am the parent shell and my pid is $$" x & echo "Just launched x and the pid is $! " y & echo "Just launched y and the pid is $! " wait Output I am the parent shell and my pid is 3107 Just launched x and the pid is 3108 I am a subshell x echo 1 and my pid is

Is command substitution $(foo) bashism?

浪子不回头ぞ 提交于 2019-11-28 23:39:32
There are two different syntaxes for command substitution, FOO=$(echo bar) and FOO=`echo bar` As far as I know, the first method is defined in Bash, while the second is defined in sh . Consider the following use of command substitution in an sh script. #!/bin/sh FOO=$(echo bar) Does that fall under the definition of bashism ? bashisms, i.e. features not defined by POSIX (won't work in dash, or general /bin/sh). It's the same thing. So no it's not a bashism nor related to bash only. Command Substitution Command substitution allows the output of a command to be substituted in place of the

Why does `if $(true) ; then … fi` succeed?

情到浓时终转凉″ 提交于 2019-11-28 23:05:55
Inspired by this question : What should an if statement do when the condition is a command substitution where the command produces no output? NOTE: The example is if $(true); then ... , not if true ; then ... For example, given: if $(true) ; then echo yes ; else echo no ; fi I would think that $(true) should be replaced by the output of the true command, which is nothing. It should then be equivalent to either this: if "" ; then echo yes ; else echo no ; fi which prints no because there is no command whose name is the empty string, or to this: if ; then echo yes ; else echo no ; fi which is a

How to get shell to self-detect using zsh or bash

北城以北 提交于 2019-11-28 22:18:39
I've a question on how to tell which shell the user is using. Suppose a script that if the user is using zsh, then put PATH to his .zshrc and if using bash should put in .bashrc. And set rvmrc accordingly. #!/usr/bin/env bash export PATH='/usr/local/bin:$PATH'" >> ~/.zshrc source ~/.zshrc I've tried the following but it does not work : ( if [[ $0 == "bash ]]; then export PATH='/usr/local/bin:$PATH'" >> ~/.bashrc elif [[ $0 == "zsh" ]]; then export PATH='/usr/local/bin:$PATH'" >> ~/.zshrc fi # ... more commands ... if [[ $0 == "bash ]]; then [[ -s '/Users/`whoami`/.rvm/scripts/rvm' ]] && source

How to get /etc/profile to run automatically in Alpine / Docker

爱⌒轻易说出口 提交于 2019-11-28 21:04:43
问题 How can I get /etc/profile to run automatically when starting an Alpine Docker container interactively? I have added some aliases to an aliases.sh file and placed it in /etc/profile.d , but when I start the container using docker run -it [my_container] sh , my aliases aren't active. I have to manually type . /etc/profile from the command line each time. Is there some other configuration necessary to get /etc/profile to run at login? I've also had problems with using a ~/.profile file. Any

Equivalent of .bat in mac os

守給你的承諾、 提交于 2019-11-28 21:01:14
问题 I currently use a .bat file that is utilized to invoke a java file. If I wanted to utilize the same functionality on Mac OS what format changes would I make? (unless the .bat equivalent on Mac OS is the .sh format?) java -cp ".;.\supportlibraries\Framework_Core.jar;.\supportlibraries\Framework_DataTable.jar;.\supportlibraries\Framework_Reporting.jar;.\supportlibraries\Framework_Utilities.jar;.\supportlibraries\poi-3.8-20120326.jar;D:\downloads\Selenium 2.0\selenium-server-standalone-2.19.0