6

I have a shell script created by someone else which I am currently trying to understand and there is a line in it which is

vim -c "1,\$s/MAJOR_VERSION = ./MAJOR_VERSION = $1/" -c "1,\$s/MINOR_VERSION = .*/MINOR_VERSION = $2/" -c "wq" $f

I know what it does is change MAJOR_VERSION = . to my input ($1), but I don't understand what the

"1, \$s

at the beginning means. The corresponding vim command from terminal would be :\s/MAJOR_VERSION... etc, so what does the $s do in this case?

13

1,$ defines the range on which your substitute command s/../../ is applied. 1,$ means 'from the first to the last line'. See :help range in Vim for more.

  • 4
    ... and it's escaped in this context to prevent the shell from expanding $s as a shell variable – steeldriver Jun 28 '18 at 12:07
  • 6
    Might be worth mentioning that you can use % as shorthand for 1,$. – JoL Jun 28 '18 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.