sed not working in bash script
This line works from bash shell cli.
GNU bash, version 5.0.0(1) But not if I place it into a bash script. In cli is does just that, adds START END after permissions tag In script, nothing happens. Bad syntax inside a script? sed -i -e "/\<permissions\>/a \<\!-- START -->\n\<\!-- END --\>" myfile |
Quote:
Some general comments, not specifically related to the script context... From your description I think the escaped brackets probably have an unintended effect as they will match an empty string at those positions, not the opening and closing brackets. I would suggest using single quotes to tone down shell expansions and all those backslashes are probably not needed either. Code:
$ cat infile Either of these work in a simple script here, so it may be your script or environment preventing success on your end, so more info would be helpful. |
Quote:
Code:
#! /system/bin/bash It's Android OS linux, but bash should be fine. |
Quote:
https://stackoverflow.com/questions/...pressions-vs-b |
Quote:
Running it from cli I end up with <permissions> <!-- START --> <!-- END --> |
Quote:
I am not familiar with the Android environment so perhaps someone else can explain the failure in script problem. |
@OP How did you test your script? There might have been error messages you didn't see. Lack of write-access-right on the file, for example.
|
the most important things are:
1. add some error handling, and some checks in your script 2. use a log file to store those information And you will see if (for example) file was not found, or sed was not found or anything else happened |
Quote:
Quote:
|
Quote:
Daniel B. Martin . |
Quote:
:) ▐ Yeah, but let me tell you why it sucks. I had that salary for past 20yrs, and I have been with only a few companies over that period, and I have advanced my skillsets and have made technical contributions to security industry! Cheap [add your fav curse word here] companies. |
With some logging and looking, found my err.
There were no errors from commands. Turns out one of my sed commands was doing what it said it should do, which was not what I needed it to do. I however thought I was testing the sequence from script on cli, but maybe I wasn't. I am still thinking about that. I reworked one sed command and now all is ok. The error was happening prior to the sed command I listed in post #3. solved. btw, sed on Android is a link to toybox, as there is no sed binary on the system. |
Quote:
You'd be amazed how often that turns out to be the problem - in any language .. |
Quote:
Quote:
|
All times are GMT -5. The time now is 07:18 PM. |