The string tag has no wiki summary.
2
votes
1answer
52 views
shell parameter substitution to rename files
I need to rename filenames which starts with "foo" into "boo"
This is the script I used
#!/bin/sh
for f in *.jpg;
do
mv -- "{$f}" "${f/foo/boo}";
done
but when i run I get a bad substitution ...
2
votes
2answers
89 views
Testing a string containing only spaces (tabs, or “ ”)?
My code below doesn't work:
stringZ=" "
if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then
echo string is blank
else
echo string is not blank
fi
Result:
string is not blank # wrong
...
2
votes
4answers
4k views
how to concatenate strings in bash?
I need to concatenate 2 strings in bash, so that:
string1=hello
string2=world
mystring=string1+string2
echo mystring should produce
helloworld
7
votes
4answers
602 views
How do I find the overlap of two strings in bash?
I have two strings. For the sake of the example they are set like this:
string1="test toast"
string2="test test"
What I want is to find the overlap starting at the beginning of the strings. With ...
1
vote
3answers
343 views
How to get the first word of a string?
When I 'echo *' I get the following output:
file1 file2 file3 ...
What I want is to pick out the first word. How can I proceed?
0
votes
3answers
105 views
Extract the base file name from a URL
url=http://www.foo.bar/file.ext; echo ${url##/*}
I expected this code to print file.ext, but it prints the whole URL. Why? How can I extract the file name?
5
votes
2answers
280 views
Extracting a string, according to a pattern, in a bash script
In bash, suppose that I have a string strname:
strname="ph7go04325r"
I would like to extract the characters between the first "3" character and the last "r" character in strname, saving the result ...
10
votes
5answers
352 views
Pattern matching on path names in bash
I want to act on a list of subdirectories in a directory. Consider:
for x in x86-headers/*/C/populate.sh; do echo $x; done
This gives
x86-headers/elf/C/populate.sh
x86-headers/gl/C/populate.sh
...
2
votes
5answers
163 views
Test if a string has a period in it with bash
I want to run a bash command on output from Drupal's drush command-line interface. drush site-alias returns a list of webroots, first showing the name of the group, and then each site in that group. ...
1
vote
2answers
139 views
Pattern matching from the input arguments
we're trying to enhance the scripts.
Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...
2
votes
2answers
97 views
Bash variables and types
I'm making a script that validate an IP address. I do this:
read pool
checkIp()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
...
0
votes
1answer
61 views
Alter path of find result [duplicate]
Possible Duplicate:
Manipulate file name piped from find command
How can I alter the path of a file found with find before I run an exec on it? I want to find files and then mv them to a ...
2
votes
2answers
215 views
How to defer variable expansion
I was wanting to initialize some strings at the top of my script with variables that have no yet been set, such as:
str1='I went to ${PLACE} and saw ${EVENT}'
str2='If you do ${ACTION} you will ...
1
vote
2answers
298 views
How to correctly concatenate strings in shells script?
I have a bash shell which I need to modify, and I have to set a variable in a script and then call another script. My variable, EXTRA_JAVA_OPTIONS must be
-javaagent:myagent.jar="-d 0 -i 1000 -l log2 ...
2
votes
3answers
186 views
Search and replacing a string on specific file extensions
I have this bash:
replace="s/AAAA/BBBB/g";
find myDirectory/. -type f -print0 | xargs -0 sed -i $replace;
that will recursively scan myDirectory tree and replace all occurrences of AAAA with ...