bash - how can I replace a line containing variables? -
i have bash script , want use replacing lines string , add date end of line:
#! /bin/bash today=`date '+%y_%m_%d__%h_%m_%s'`; sed -i '3s/.*/config_localversion=/' ~/desktop/file1 file2 ... also, can range of files start string "file"?
to use variable expansion in bash, variables must non-quoted or double-quoted. single quotes prevent expansion. on other hand, you'd want avoid expansion of * in 3s/.*/ in case have directory 3s containing files starting ..
fortunately, can chain strings together, can do
#!/bin/bash today=$(date '+%y_%m_%d__%h_%m_%s'); sed -i '3s/.*/config_localversion='"$today"'/' ~/desktop/file{1,2,foo} and can range of file start string "file" ?
the glob ~/desktop/file{1,2,foo} expand ~/desktop/file1 ~/desktop/file2 ~/desktop/filefoo. if instead want match files on desktop name starting 'file', use ~/desktop/file* instead.
Comments
Post a Comment