scripting

How to make an “alias” for a long path?

主宰稳场 提交于 2019-12-18 10:00:52
问题 I tried to make an "alias" for a path that I use often while shell scripting. I tried something, but it failed: myFold="~/Files/Scripts/Main" cd myFold bash: cd: myFold: No such file or directory How do I make it work ? However, cd ~/Files/Scripts/Main works. 回答1: Since it's an environment variable (alias has a different definition in bash ), you need to evaluate it with something like: cd "${myFold}" or: cp "${myFold}/someFile" /somewhere/else But I actually find it easier, if you just want

Redirecting arguments into a program (BASH)

允我心安 提交于 2019-12-18 09:47:37
问题 I am fairly new to bash scripting and a part I am stuck on is after done< "$file_input" What I am trying to achieve is when I run the program ./test inside the testfile contains the numbers 15 14 90 22 and the program is going to take those numbers as the arguments and run it, but I am quite unsure how to do that. Am I going in the correct direction? Thanks for any help if [[ "$#" -ne 1 ]] then writeusage exit fi your_path=../file/test test_path=../../public/test file_input="$1" while read -r

Reading each line as argument in bash

丶灬走出姿态 提交于 2019-12-18 09:45:56
问题 I am trying to learn bashing. I am trying to run ./test testcase the file in test case has the arguments 9 11 22 13, 32 35 32 16 on the next line and so on My program takes 4 arguments. Right now if testcase has one line of arguments i.e 3 5 6 7 it works fine, but when there is more than 2 it can't run the program properly. I know I need a while loop to read each line of the file, but I am stuck here. If someone could help me it would be greatly appreciated. Thank you in advance. I've asked

Powershell to search for files based on words / phrase but also Zip files and within zip files

主宰稳场 提交于 2019-12-18 09:36:28
问题 I have this script... Which looks at a given network location and then goes through all the folders / subfolders to search for specific words / phrases. Looking to modify to be able to do the same for ZIP files. Working in the same manner, report back any ZIP files which contain the words set out but also any files within the ZIP... Any help? "`n" write-Host "Search Running" -ForegroundColor Red $filePath = "\\fileserver\mydepts\IT" "`n" Get-ChildItem -Recurse -Force $filePath -ErrorAction

Time Variables in Bash Scripting

不打扰是莪最后的温柔 提交于 2019-12-18 09:33:58
问题 If I have 3 different scripts to run at various times each time a file is written to, how would a bash script be written to run a specific script only at a specific time. This is not as simple as a cron job (though cron could probably swap out the .sh file based on time), I am looking for the time variables. For instance: If 9am-11:30 am run scriptA.sh if file.txt is changed. If 11:30am-5:45pm run scriptB.sh if file is changed. If 5:46pm-8:59am run scriptC.sh if file is changed. I asked a

command substitution doesn't work with echo in makefile [duplicate]

大城市里の小女人 提交于 2019-12-18 09:29:23
问题 This question already has answers here : Why doesn't my Makefile interpolate an expression in a command (2 answers) Closed last year . Here's a simple command that works fine in my bash shell: echo "Created at: $(date)" >> README.md It appends Created at: Wed Jan 24 10:04:48 STD 2018 to README.md. However, ii I include the same command in my makefile, the behavior is different. makefile: README.md: echo "Created at: $(date)" >> README.md Running make README.md will treat the command

Flattening and filtering a complex structure in ansible - dict of list of dict

不想你离开。 提交于 2019-12-18 09:08:48
问题 I have data that is represented in this manner: { "key1": [{ "name": "some name1", "index": "some idx1" }, { "name": "some name2", "index": "some idx2" }, { "name": "some name3", "index": "some idx3" }], "key2": [{ "name": "some name4", "index": "some idx4" }, { "name": "some name5", "index": "some idx5" }, { "name": "some name6", "index": "some idx6" }] } I would like to convert the above to this, which is basically a dictionary with the existing key to a list of the indices. { "key1": [some

Add blank line between lines from different groups

拈花ヽ惹草 提交于 2019-12-18 08:58:28
问题 I have a file A of the form (frequency,file name,code lines): 1 file_name1 code_line1 2 file_name2 code_line2 2 file_name2 code_line3 2 file_name3 code_line4 2 file_name3 code_line5 3 file_name4 code_line6 3 file_name4 code_line7 3 file_name4 code_line8 I want output B as: 1 file_name1 code_line1 2 file_name2 code_line2 2 file_name2 code_line3 2 file_name3 code_line4 2 file_name3 code_line5 3 file_name4 code_line6 3 file_name4 code_line7 3 file_name4 code_line8 Basically the file A contains

How to tell the difference between a VBscript is run from command line or by clicking it in a window?

时光总嘲笑我的痴心妄想 提交于 2019-12-18 08:46:49
问题 All I want to do is differentiate between the program being run by the command line or by clicking the test.vbs file in a window. If you run the script by typing C:\testFolder\test.vbs in a command prompt, then I want the program to run differently than if you double clicked test.vbs in the testFolder . Is there some system variable that I can use to differentiate between the two scenarios? I first attempted to use WScript.Fullname to determine if the pathname ended in cscript or wscript. But

How to debug a bash function that returns a value, and how to add newlines to a variable?

风格不统一 提交于 2019-12-18 08:01:08
问题 I'm in a bash crash course today. This is a bash function that returns a value, via echo: #!/bin/bash get_hello_name() { echo 'Hello $1!' } msg=$(get_hello_name "x") echo $msg Output: $ bash ./initial_script5.sh Hello $1! I then incorrectly thought that the last echo was returned (I come from Java and Python), and was trying to use echo to debug the rest of the function. And then I was wondering why the heck I could not print out newlines in my echo statements, despite trying every single