In my bash script I have an external (received from user) string, which I should use in sed pattern.
REPLACE="<funny characters here>"
sed "s/KEYWORD/$REPLACE/g"
How can I escape the $REPLACE string so it would be safely accepted by sed as a literal replacement?
NOTE: The KEYWORD is a dumb substring with no matches etc. It is not supplied by user.
Hi,
I get in a bash script, in the follwoing line
echo $AAAA" "$DDDD" "$MOL_TAG >> ${OUPUT_RESULTS}
the error:
line 46: ${OUPUT_RESULTS}: ambiguous redirect
Why?
Thanks
i have never used PHP with CLI, but i have seen scripts run with php code.
i was wondering, why should we use bash, when php is so popular and is able to run in CLI.
what are the pros and cons with each one?
should i use php for all CLI scripting in the future?
Hi,
this is probably a very stupid question; in a bash script, given the output of, for instance;
awk '{print $7}' temp
it gives 0.54546
I would like to give this to a variable, so I tried:
read ENE <<< $(awk '{print $7}' temp)
but I get
Syntax error: redirection unexpected
Could you tell me why, and what is the easiest way to do this assignment?
Thanks
Given file names like these:
/the/path/foo.txt
bar.txt
I hope to get
foo
bar
Why this doesn't work?
#!/bin/bash
fullfile=$1
fname=$(basename $fullfile)
fbname=${filename%.*}
echo $fbname
What's the right way to do it?
Hello,
I'd like to include a config file in my bash script with 2 conditions:
1) the config file name is constructed on-the-fly and stored in variable, and 2) in case if config file doesn't exist, the script should fail:
config.cfg:
CONFIGURED=yes
test.sh:
#!/bin/sh
$CFG=config.cfg
echo Source command doesn't work here:
[ -f $CFG ] && ( source $CFG ) || (echo $CFG doesnt exist; exit 127)
echo $CONFIGURED
echo ... but works here:
source $CFG
echo $CONFIGURED
What's wrong in [...] statement?
I've found many useful Bash commands that can execute OS X behaviors from the command line such as:
screencapture -x -C $FILENAME
Is there such a command that can check if the screen saver is active?
I need a bash command that will convert a string to something that is escaped. Here's an example:
echo "hello\world"|escape|someprog
Where the escape command makes "hello\world" into "hello\\world". Then, someprog can use "hello\world" as it expects. Of course, this is a simplified example of what I will really be doing.
Is there any variable in bash that contains the name of the .sh file executed ?
The line number would be great too.
I want to use it in error messages such as:
echo "ERROR: [$FILE:L$LINE] $somefile not found"
Thank you
In perl you can simply write print "-" x 20 and you get a line with dashes...but i need the same thing in bash/commandline on linux without perl/(g)awk etc. any ideas? The intention is to use it in the -exec of the find command and i want to prevent using simple echo "---------" ...
In a Windows command script, one can determine the directory path of the currently executing script using %~dp0. For example:
@echo Running from %~dp0
What would be the equivalent in a BASH script?
Hi,
how can one turn off the error messages of a bash script?
I want to turn it off, and handle the expected ones by myself
For instance, when it does not find some files, to show my specific error message.
Thanks
Hi,
I am writing a python script on Linux for twitter post using API, Is it possible to pass symbols like "(" ")" etc in clear text without apostrophes....
% ./twitterupdate this is me #works fine
% ./twitterupdate this is bad :(( #this leaves a error on bash.
Is the only alternative is to enclose the text into -- "" ?? like..
% ./twitterupdate "this is bad :((" #this will reduce the ease of use for the script
Is there any workaround?
Greetings!
I have a text file with parameter set as follows:
NameOfParameter Value1 Value2 Value3 ...
...
I want to find needed parameter by its NameOfParameter using regexp pattern and return a selected Value to my Bash script.
I tried to do this with grep, but it returns a whole line instead of Value.
Could you help me to find as approach please?
Each day an application creates a file called file_YYYYMMDD.csv where YYYYMMDD is the production date. But sometimes the generation fails and no files are generated for a couple of days.
I'd like an easy way in a bash or sh script to find the filename of the most recent file, which has been produced before a given reference date.
Typical usage: find the last generated file, disregarding those produced after the May 1st.
Thanks for your help
Hi,
I am having a look af a big C++ project with more than 100 files. Given a certain function name, how can one find just using bash tools like find or grep, the declaration and the defintion of a function?
Thanks
I'm writing a bash script to modify a config file which contains a bunch of key, value pairs. How can i read the key and find the value and possibly modify it?
I'm trying to wrap a standard sequence of steps in a shell script (linux/bash) and can't seem to figure out how to tell of the execution of svn status returned anything. For example
~/sandbox/$svn status
? pat/foo
~/sandbox/$echo $?
0
If I delete the foo file, then the
svn status
return nothing, but the echo $? is still 0
I want to not do some steps if there are uncommitted changes.
Pointers greatly appreciated.
i have text such as
http://pastebin.com/H8zTbG54
we can say this text is set of rules splitted by "OR" at the end of lines
i need to put set of lines(rules) into buckets (bash array members) but i have character limit for each array member which is 1024
so each array member should contain set of rules but character count for each array member can not exceed 1024
can anybody help me to do that
solaris 10
Hi!
I have a file
line a - this is line a
line b - this is line b
line c - this is line c
line d - this is line d
line e - this is line e
The question is: How can I output the lines starting from "line b" till "line d" using bash commands?
I mean, to obtain:
"line b - this is line b
line c - this is line c
line d - this is line d"
I want to create a near 100% load on a Linux machine. It's quad core system and I want all cores going full speed. Ideally, the CPU load would last a designated amount of time and then stop. I'm hoping there's some trick in bash. I'm thinking some sort of infinite loop.
Hi,
when compiling some projects on linux terminal, I get usually a long output consisting of a lot of information. Usually this information is MONOCHROME. I wonder if bash can be modified somehow, so in all outputs or in some specific outputs (like from Makefile, etc) I can get different colors dependeing on, for instance:
make[1]: Leaving directory
or
g++ -DHAVE_CONFIG_H -I.
etc.
Thanks
Dear all,
I'm a newbie in bash and I would like to pass as parameter to a python function all files in a directory that don't match a given pattern. sth. like:
$myscripts/myprog.py $myfiles/!(bonjovi)
The above example should retrieve all files that don't match to "bonjovi".
Best wishes