Posts

Showing posts with the label bash

Shell Jenkins job reading text from file with variables

Shell Jenkins job reading text from file with variables I am implementing Jenkins job in bash shell script. Jenkins jobs is using the variable AS_OF_DATE which can be used as input for users. AS_OF_DATE I also have some files on zone with text that I grep during the execution of this jenkins job. So user will start the jobs and given parameters is: AS_OF_DATE: "20180331" AS_OF_DATE: "20180331" Then during the job I grep some text from test.txt file. test.txt TEXT_FROM_FILE="This is my text, where i used ${AS_OF_DATE}" And when I do the echo of $TEXT_FROM_FILE , variable $AS_OF_DATE is not changed with the date that user added. $TEXT_FROM_FILE $AS_OF_DATE My outcome is: "This is my text, where i used ${AS_OF_DATE}" What it should be: "This is my text, where i used 20180331" "This is my text, where i used 20180331" I assume that I am not declaring the variable inside the file correctly, so my question is hot to correctly spe...

How to make search, enter text and replace a line in bash?

How to make search, enter text and replace a line in bash? I've been trying to write a bash code (experimenting) where bash will ask (Enter Text) and the user will enter a certain text lets say (I am new) and the text (I am new) will be moved to a line called User=I am new. So, here is a cfg file named xyz.cfg User Name Address Country and here is the bash script called test and with only echo $Input > $file the bash replace the whole file with the entered text but I want to keep the config as it is and add the Enter Text: value to the line User but this doesn't help, the code below, #! /bin/sh file=/root/xyz.cfg echo "Enter text:" read Input echo $Input > $file **(confused here)** **(it replaces the whole cfg)** Another line I thought of is here, but it doesn't work. I am not good with these so I hope it's solved; I tried searching the web with zero luck. (doesn't work) #! /bin/sh file=/root/xyz.cfg echo "Enter text:" read Input echo ...

Terminal -bash: command not found errors

Terminal -bash: command not found errors I messed up something in my programming a few days ago that screwed up my terminal. My terminal now gives me the a bash error message with basic functions like ls, cd, or ssh. The error looks like this: -bash: ls: command not found , where the "ls" can be replaced with any shell command. The only way I have found to make my terminal function, is by inputting: export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin" into ever terminal window I open, which can get very tedious. It also refuses to run Python or Jupyter unless I type the aforementioned command in the terminal window first. Go files also fail to run in terminal, and gives me a similar error message: -bash: go: command not found. This can be overcome by inputting: export PATH=$PATH:/usr/local/go/bin into the terminal window first. I'm really worried about what is going on in my computer, and need my terminal to keep functioning in order for me to finish and pass th...

Combine for loop with cat and json2html

Combine for loop with cat and json2html I try to convert json files to html files. So I can later import them to the website. My idea is run json2table to create a table and write then to the html directory. But I find not out how can redirecting the output of json2table. for file in $(ls json/*.json); do cat $file | json2table > html/$file.html; done But this end with bash: html/json/26.json.html: No such file or directory Is there someone which can help to fix the error? Thank you Silvio Check content of $file and html/$file.html in your loop. – Cyrus Jul 1 at 19:27 $file html/$file.html 3 Answers 3 Your ${file} includes the json directory. When you don't have a directory html/json the redirection will fail. I think you have a subdir html ...

How to check the checksum through commandline?

How to check the checksum through commandline? I want to do something like this on commandline on my UNIX variant if (shasum httpd-2.4.7.tar.bz2 == 19asdasdasd56462e44d61a093ea57e964cf0af05c0e) echo 'good to go' I dont want to write a separate script text page just to check this. This above thing is showing syntax error. But there must be a slick way to get around this? How to do this? 8 Answers 8 shasum httpd-2.4.7.tar.bz2 | awk '$1=="19asdasdasd56462e44d61a093ea57e964cf0af05c0e"{print"good to go"}' So normally you get this output from shasum What my command does it is takes the first field $1 , and compares it against your string. If the strings match, then awk prints "good to go". $1 "good to go" dude – John Doe Feb 22 '14 at 16:58 ...

How to escape single quotes within single quoted strings?

How to escape single quotes within single quoted strings? Let's say, you have a bash alias like: alias alias rxvt='urxvt' which works fine. However: alias rxvt='urxvt -fg '#111111' -bg '#111111'' won't work, and neither will: alias rxvt='urxvt -fg '#111111' -bg '#111111'' So how do you end up matching up opening and closing quotes inside a string once you have escaped quotes? alias rxvt='urxvt -fg'''#111111''' -bg '''#111111''' seems ungainly although it would represent the same string if you're allowed to concatenate them like that. Do you realise that you don't need to use single quotes for alias? Double quotes is much easier. – teknopaul Jan 9 '16 at 23:58 See also: Difference betwee...