0

I am using Windows 10 and am on Lab 5 of the Git Immersion tutorial, with Git Bash as my shell.

I've used echo 'puts "Hello, World"' > hello.rb to create the hello.rb file per the following: how to create a file with the cmd?

I am to change our hello program to take an argument from the command line. Change the file to be:

puts "Hello, #{ARGV.first}!"

I've thought of using Sublime Text to edit the file, but I feel compelled to use Git Bash. How could I edit the file in Git Bash?

Thanks!

pjs
  • 18,696
  • 4
  • 27
  • 56
Jeffrey
  • 7
  • 1
  • 1
  • 6
  • 2
    Why do you feel compelled to use Git Bash? Sublime Text sounds to me like the right tool for the job. – Lucas Wilson-Richter Feb 21 '17 at 01:44
  • 1
    @Haoyu: You want to edit a file without using a text editor???? When you are in the mood to punish yourself, there are plenty of well-tried methods.... – user1934428 Feb 21 '17 at 06:42
  • @user1934428 Would it be possible to edit with a text editor such as emacs in Git Bash? I know it works for commit comments. – Jeffrey Feb 21 '17 at 16:10
  • 1
    I have never thought that people might want to use anything else than a text editor. I'm just wandering: How did you edit your programs before? And why is this related to what shell you are using? – user1934428 Feb 22 '17 at 07:42

2 Answers2

4

The best way for me to edit a file in Git Bash is the command 'nano fileName.txt'. This command opens editing mode. After having your work done, press Ctrl + x. Then approve changes with "y" to finally exit nano.

Maksym Dudyk
  • 1,082
  • 14
  • 16
1

Use GNU sed to substitute text.

sed -i "s/World/#{ARGV.first}\!/" hello.rb

cat hello.rb  
puts "Hello, #{ARGV.first}!  

https://www.gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command

edit: Or use a command line editor such as vi or vim.

pleh2
  • 38
  • 4