Bash replacing content INLINE using a WGET and CAT commands [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I am working on some kind of version control for a specific software (Bash script.)
When a new version releases, the code should be updated to the latest release, I have figured this out but I seem stuck and can't make the replacement inline.
#First we download the source code with wget, it returns a text with the new code
wget www.example.com/sourcecode | cat . > $0
How can I redirect that output (text / script) to the current script who's executing it and replace it.
Note $0 gives us the location of the current script. So the cat command, just should replace the new text coming from wget to the current script.
Thanks!

Your question is a bit confused, so I can try to guess your needs.
Are you asking how to capture the output of the commmand you posted?
If yes, the solution is:
source_file_content=$(wget -O - http://www.example.com/sourcecode)
# Do anything with ${source_file_content}
Let me know if it is right for you.

Related

Store Linux Terminal output to file [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I would like store the terminal output to a file. I execute the command and cannot view the terminal output in the file but I am able to view the output in the terminal. Kindly help.
./bbmap.sh in=sequence.fasta covstats=constats.txt covhist=covhist.txt basecov=basecov.txt bincov=bincov.txt > output.txt
Validate the output of the script without redirecting to a file.
You can also pipe the output through tee so the output will be shown before sending it to a file.
script.sh |tee script_output.txt
Found the problem, add "command 2> file". T

How to write shell script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to Linux commands. I have a requirement where I want to start Tomcat using a shell script. The location of startup.sh file is in /usr/lib/apache-tomcat-7.0.14/bin/. Tomcat is starting using command sh startup.sh. I want to create a shell script so that it will go to that folder and will execute sh startup.sh command. How can I do this using a shell script? Can anyone share the script for doing this?
Are you serious?
#!/bin/bash
cd /usr/lib/apache-tomcat-7.0.14/bin/
sh startup.sh
#!/bin/bash
exec /usr/lib/apache-tomcat-7.0.14/bin/startup.sh
is simpler (as does not have a shell kicking around)

How can I create .sh extension file in Linux Ubuntu? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to write a script to run one of my .jar files as daemons, but I am not understanding how to create a .sh extension file in Ubuntu. I have already used vi to create a file with the code that I want, but I cannot figure out how to define the file to specifically be a .sh file. For example, I want to convert my file "foo" or "foo.txt" into "foo.sh".
Is there a simple command I am not seeing that can convert files to a .sh extension or is it a more complicated process?
Use this as a template:
#!/bin/bash
# content of your script
The first line is called a shebang and tells the OS what program that should be used executing the content of the file, in this case, bash.
To make the file executable:
chmod 755 foo.sh
To execute your script do:
./foo.sh

Changing the current working directory of invoking bash programmatically [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a file which contains key/value -pairs in the format
TAG PATH
. Now, I want to write a program that reads from the command line a TAG, and changes the current working directory of invoking bash to corresponding PATH.
How would I go about this?
You might consider something like (perhaps in your bash function)
while read tagname dirname ; do
pushd $dirname ;
dosomethingwith $tagname
popd
done < yourinputfile.txt
See this question (about read in bash) and read the advanced bash scripting guide
GNU awk might be a better tool.
Notice that you can only change the current directory of the current process using the chdir(2) syscall (invoked by cd or pushd or popd bash builtins). There is no way to change the directory of some other process (e.g. the parent or invoking one). The pushd and popd builtins also updates bash directory stack.
There is no way to change the current directory of the invoking shell (the parent process running in a terminal). But you may define your own bash function there. Read Advanced Linux Programming to understand more about Unix processes

How to rename files in a directory using bash script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I wanted to find a bash script for renaming files with _ (underscore) to - (hyphen)
for example changing file name my_page_name.php to my-page-name.php,
keeping the name of the file of those without .php extension same
I attempted:
Nothing yet , just used the script found here bbs.archlinux.org/viewtopic.php?id=36305 and replace space with _ and underscore with -
If you only need to do it in one directory (and not subdirectories):
for f in *_*; do mv "$f" "${f//_/-}"; done
Otherwise, you can use find to -exec a bash subshell.
Use the rename program:
rename s:_:-: *.php

Resources