Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed gives "sed: 1: "tsunit.js": undefined label 'sunit.js'"

Tags:

bash

makefile

sed

Short questing, why does this line

sed -i '1s/^/#!\/usr\/bin\/env node\n/' tsunit.js;\

Give me this error

sed: 1: "tsunit.js": undefined label 'sunit.js'

in a Makefile, if relevant.

I’m on a Mac.

like image 876
SomeNorwegianGuy Avatar asked Apr 14 '14 22:04

SomeNorwegianGuy


2 Answers

According to the Apple man page for sed, the -i option takes a required argument specifying the file extension for the backup file. As a result, assuming that you are on a Mac or similar, sed believes that you intended '1s/^/#!\/usr\/bin\/env node\n/' to be the file extension of the backup. It then interprets tsunit.js as a sed command. the leading t tells sed to branch to the label sunit.js which, of course, doesn't exist. Hence the error message.

The solution is:

sed -i '.bak' '1s/^/#!\/usr\/bin\/env node\n/' tsunit.js

Or, if you really do not want a backup:

sed -i '' '1s/^/#!\/usr\/bin\/env node\n/' tsunit.js
like image 71
John1024 Avatar answered Sep 20 '22 14:09

John1024


Also, it looks like you're inserting a line. sed has more commands than s

sed -i "" '1i\
#!/usr/bin/env node' tsunit.js
like image 42
glenn jackman Avatar answered Sep 19 '22 14:09

glenn jackman