Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Sed und Variabeln $

Empfohlene Antworten

Veröffentlicht

Hi,

kleines Problem:

/bin/sed -n -e "s/\(^[a-zA-Z]*\):$VAR:N$/\1/gp" /etc/test

funtkioniert nicht -> Unknown option to `s'

Wie kann ich eine Env Variable einfügen?

Beim googeln hatten die alle ' statt ". Das ist bei mir nicht der Fall.

Gruß Scratch

Mit single-quotes dürfte es auch nicht gehen, weil dann die Variablen nicht von der shell expandiert werden.

Ich kann den Fehler jedoch nicht nachvollziehen.

sed-Version?

Wie sieht /etc/test aus und was willst du Substituieren?

Was ist der Wert deiner Variable?

user@host:~> cat testfile.txt

foo:bar

blubb:omg

k:thxbye

bar:foo

user@host:~> VALUE=omg; sed -e 's/^\([a-zA-Z]*\):$VALUE$/\1/g' testfile.txt

foo:bar

blubb:omg

k:thxbye

bar:foo

Single-Quotes tun nicht, weil hier nach $VALUE gesucht wird, nicht nach dem Inhalt der Variable VALUE

user@host:~> VALUE=omg; sed -e "s/^\([a-zA-Z]*\):$VALUE$/\1/g" testfile.txt

foo:bar

blubb

k:thxbye

bar:foo

Tut, weil hier die Shell $VALUE erst auswerted und dann an sed gibt.

  • Autor

Hi,

der Befehl lautet genau:

/bin/sed -n -e "s/^\([a-zA-Z]*\):$ORACLE\_HOME:N/\1/gp" /etc/oratab

die sed Version ist: 4.0.7

# echo $ORACLE_HOME

/opt/app/oracle/product/inf904

/etc/oratab

*:/opt/app/oracle/product/inf904:N

iasdb:/opt/app/oracle/product/inf904:N

Der Fehler ist:

/bin/sed: -e expression #1, char 23: Unknown option to `s'

Gruß Scratch

...

Natürlich geht das nicht

Der Wert deiner Variable enthält Slashes. Die musst du schon escapen, weil sie sonst sed interpretiert.

Mit

ORACLE_HOME=/opt/app/oracle/product/inf904

wird aus deinem Command:

/bin/sed -n -e "s/^\([a-zA-Z]*\):/opt/app/oracle/product/inf904:N/\1/gp" /etc/oratab

und das sind ein paar zuviel /// für sed.

Weich auf alternative Trenner aus oder escape die /'s im OraPath durch \/

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.