sh

Is ./*/ portable?

家住魔仙堡 提交于 2021-02-19 04:27:06
问题 I often use ./*/ in a for loop like for d in ./*/; do : # do something with dirs done to match all non-hidden directories in current working directory, but I'm not really sure if this is a portable way to do that. I have bash, dash and ksh installed on my system and it works with all, but since POSIX spec doesn't say anything about it (or it says implicitly, and I missed it) I think I can't rely on it. I also checked POSIX bug reports, but to no avail, there's no mention of it there as well.

Bash SH Script - Rename File with specific extension + Move to specific location

眉间皱痕 提交于 2021-02-18 19:43:39
问题 SEE VISUAL EXPLANATION and EDIT I'm trying to create a bash script to do a rename+move. This is the example situation: |DOCTEMP - NameOfTheFolder---------|NameOfADocument.docx FOLDER---| |DOCFINAL - OtherNameOfTheFolder---|OtherNameOfADocument.pdf | |etc. What I want to do is a script that: Part I Only if the file has docx, pdf, ppt then rename it as its folder but without DOCTEMP - / DOCFINAL - . NameOfADocument.docx => NameOfTheFolder.docx OtherNameOfADocument.pdf => OtherNameOfTheFolder

“${0%/*}” and “${0##*/}” in sh [duplicate]

大憨熊 提交于 2021-02-15 11:56:15
问题 This question already has answers here : Bash: manipulating with strings (percent sign) (1 answer) What is the meaning of the ${0##…} syntax with variable, braces and hash character in bash? (3 answers) Closed 15 days ago . These are excerpts from a brew command. BREW_FILE_DIRECTORY=$(chdir "${0%/*}" && pwd -P) export HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}" What do ${0%/*} and ${0##*/} mean in shell? 回答1: These are shell parameter expansions: ${var%/*} - remove everything after the

BASH: How to find no. of days (considering only “Network / Business Days”) between two dates (i.e. exclude weekends Saturday/Sunday)

蹲街弑〆低调 提交于 2021-02-12 11:33:30
问题 RHEL 7.5 BASH GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) In MS Excel , I'm able to use Network days to find no. of days between two dates. Wondering if it's possible using bash as first preference (--or any other pre-installed language on Linux supporting to solve this possibly using a one-liner - my second preference). I'm not sure if there exists any library or custom tool/utility in Linux which calculates this value. To calculate the number of workdays between two dates,

BASH: How to find no. of days (considering only “Network / Business Days”) between two dates (i.e. exclude weekends Saturday/Sunday)

半城伤御伤魂 提交于 2021-02-12 11:33:18
问题 RHEL 7.5 BASH GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) In MS Excel , I'm able to use Network days to find no. of days between two dates. Wondering if it's possible using bash as first preference (--or any other pre-installed language on Linux supporting to solve this possibly using a one-liner - my second preference). I'm not sure if there exists any library or custom tool/utility in Linux which calculates this value. To calculate the number of workdays between two dates,

In order : launch new terminal, launch R environment in the new terminal, execute commands in R environment

被刻印的时光 ゝ 提交于 2021-02-11 07:34:57
问题 I would like a shell script that launches a new terminal, opens the R environment in the terminal and executes commands in the R environment of the new terminal. Here's what I did which is not working : #!/bin/sh for i in $(seq 25) do gnome-terminal -x sh "R; source('source.r'); function($i)" done Where, function() is an r function in the file "source.r" Please help. N.B. I don't want to launch the program using the command "Rscript" EDIT 1 : I don't want to use the command Rscript because

In order : launch new terminal, launch R environment in the new terminal, execute commands in R environment

亡梦爱人 提交于 2021-02-11 07:32:42
问题 I would like a shell script that launches a new terminal, opens the R environment in the terminal and executes commands in the R environment of the new terminal. Here's what I did which is not working : #!/bin/sh for i in $(seq 25) do gnome-terminal -x sh "R; source('source.r'); function($i)" done Where, function() is an r function in the file "source.r" Please help. N.B. I don't want to launch the program using the command "Rscript" EDIT 1 : I don't want to use the command Rscript because

How to pass backslashes argument to a script?

可紊 提交于 2021-02-10 23:28:58
问题 I just want to append an user input argument in a text file. I'm using the following command: echo "$2" >> "./db.txt" $2 is expected to user to set a path like: D:\Projects\MyProject . It writes to the file, but with no backslashes. The result is: D:ProjectsMyProject I can't find anywhere how to fix that. I've tried using -e or -E params(taken from here) but it doesn't seems to make difference in this case. 回答1: You have to escape backslashes in the shell: \\ , or put the string in quotes.

How to pass backslashes argument to a script?

跟風遠走 提交于 2021-02-10 23:26:25
问题 I just want to append an user input argument in a text file. I'm using the following command: echo "$2" >> "./db.txt" $2 is expected to user to set a path like: D:\Projects\MyProject . It writes to the file, but with no backslashes. The result is: D:ProjectsMyProject I can't find anywhere how to fix that. I've tried using -e or -E params(taken from here) but it doesn't seems to make difference in this case. 回答1: You have to escape backslashes in the shell: \\ , or put the string in quotes.

ng build command is not working via jenkins build execute shell

大城市里の小女人 提交于 2021-02-10 18:38:18
问题 In jenkins build execute area I put these command: cd /var/lib/jenkins/workspace/test/ ng serve Here is the screenshot: I am getting an error like this: cd /var/lib/jenkins/workspace/test/ ng serve Environment variable TERM not defined! Build step 'Execute shell' marked build as failure Finished: FAILURE node v6.10.0 @angular/cli: 1.0.6 Please help me to resolve this issue. 回答1: Try this I did jenkins integration today. npm run ng build This is working fine. 回答2: In my case my slave Jenkins