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: text durch inhalt einer Variable ersetzen

Empfohlene Antworten

Veröffentlicht

in der Variable "backupdir" ist folgender String gespeichert:

--backup-dir=$zdir/../backup$datum/ 
in der Variable "zdir" :
/home/just2blue4u/synctest/dir-2/
hier schicke ich den Inhalt an sed, wo dann die Stelle "$zdir" durch den Inhalt der Variable "zdir" ersetzt werden soll:
echo $backupdir  | sed 's/$zdir/\($zdir\)/g' >> options.tmp
das ist falsch, denn in der options.tmp steht nach dem Schreiben:
--backup-dir=($zdir)/../backup$datum/

Ich hab schon alles mögliche ausprobiert, komme aber einfach nicht auf die richtige Schreibweise!

>> wer kann mir helfen? << :confused:

Du benutzt single quotes ('), da werden Variablen nicht expandiert.


zdir=blubb && echo '$zdir/bbbb' | sed -e 's/\$zdir/$zdir/'

$zdir/bbbb


zdir=blubb && echo '$zdir/bbbb' | sed -e "s/\$zdir/$zdir/"

blubb/bbbb

Wie du siehst geht es aber bei doublequotes, wobei du dann das erste $ escapen musst damit es da als $ steht, und nicht expandiert wird.

hab das jetzt so:

echo $backupdir  | sed -e "s/\$zdir/$zdir/" >> options.tmp
Ergebnis:
$zdir = /home/just2blue4u/synctest/dir-2/

/home/just2blue4u/synctest/dir-2/ = /home/just2blue4u/synctest/dir-2/

sed: -e Ausdruck #1, Zeichen 10: Unbekannte Option betreffs `s'
... und nun? wenn ich das script mit sh -x ausführe kommt:
+ sed -e 's/$zdir//home/just2blue4u/synctest/dir-2//'

... der Inhald der Var wird also schon eingefügt. Was ist das denn jetzt was den Fehler schmeisst?

THX schonmal für die Hilfe!

Du benutzt in deinen Variablen Slashes (/) und ebenso als Trenner für dein sed - das geht natürlich in die Mauer.

Benutz statt sed -e "s/.../.../" mal sed -e "s#...#...#"

ich muss in sed ein anderes Zeichen für "/" nehmen, weil er sonst den "/" aus der Variable als trennzeichen interpretiert...

der debug-modus der shell wirkt wunder! ^^

danke aber nochmal für deinen Hinweis!

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.