Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

string manipulation in shell

#To replace the first occurrence of a pattern with a given string,
#use ${parameter/pattern/string}:

#!/bin/bash
firstString="I love Suzi and Marry"
secondString="Sara"
echo "${firstString/Suzi/$secondString}"    

# prints 'I love Sara and Marry'

#To replace all occurrences, use ${parameter//pattern/string}:

message='The secret code is 12345'
echo "${message//[0-9]/X}"           
# prints 'The secret code is XXXXX'


#(This is documented in the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion".)
Comment

PREVIOUS NEXT
Code Example
Shell :: git go back to previous commit remote branch 
Shell :: Install docker with apt command 
Shell :: kill linux port 
Shell :: kill process running on port linux 
Shell :: bash scripting string comparison 
Shell :: pipe shell output to vim 
Shell :: git remove local changes and pull 
Shell :: create a zip file in linux 
Shell :: wkhtmltopdf javascript 
Shell :: check directory size 
Shell :: install chrome ubuntu automatic update 
Shell :: git reset last commit 
Shell :: Shell CLI Argument Default Value 
Shell :: linux require a password to open a certain file 
Shell :: find process on linux 
Shell :: shell foreach line 
Shell :: bash grep find lines that start with word 
Shell :: etcher download ubuntu 18.04 
Shell :: remove local images 
Shell :: check user terminal 
Shell :: run cmd as administrator command line 
Shell :: get total file size linux 
Shell :: awk if else 
Shell :: install from tar gz file unix 
Shell :: list of files in git commit 
Shell :: install yt-dlp windows 
Shell :: Installing plugins with vim-plug 
Shell :: Failed at the sharp@0.16.2 install script 
Shell :: how to run a command on startup in linux ubuntu or centos 
Shell :: How to install LAMP in Ubuntu 18.04? 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =