0

I'm trying to do the following:

vim +$line $LEDGER

But instead of opening at the line number it's opening two files, one the number and the other the actual file I want to open.

2
  • It works for me (bash on Mac OS X). Are you sure that $line and $LEDGER are defined? $ echo $line $LEDGER. Apr 7, 2014 at 3:03
  • 1
    It could be that that $line has leading whitespace.
    – garyjohn
    Apr 7, 2014 at 4:26

1 Answer 1

2

Probably, there is leading whitespace before the number in $line. There are several ways to fix this:

proper quoting

$ vim "+$line" "$LEDGER"

Note that it's always a good practice to quote variables, even if they currently don't contain whitespace or other problematic characters.

remove whitespace

$ vim +${line# } "$LEDGER"
2
  • I was doing wc -l $LEDGER and didn't realize it was adding the filename onto the output. I switch to wc -l $LEDGER | awk '{print $1}
    – jpiasetz
    Apr 7, 2014 at 13:38
  • Ah! You could also use cat $LEDGER | wc -l, or ${line% *}. Apr 7, 2014 at 14:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .