how to edit XML using bash script?

To change tag‘s value to 2 and tag1‘s value to 3, using XMLStarlet: xmlstarlet ed \ -u ‘/root/tag’ -v 2 \ -u ‘/root/tag1’ -v 3 \ <old.xml >new.xml Using your sample input: xmlstarlet ed \ -u ‘/root/tag’ -v 2 \ -u ‘/root/tag1’ -v 3 \ <<<‘<root><tag>1</tag><tag1>2</tag1></root>’ …emits as output: <?xml version=”1.0″?> <root> <tag>2</tag> <tag1>3</tag1> </root>

Should I use a Shebang with Bash scripts?

On UNIX-like systems, you should always start scripts with a shebang line. The system call execve (which is responsible for starting programs) relies on an executable having either an executable header or a shebang line. From FreeBSD’s execve manual page: The execve() system call transforms the calling process into a new process. The new process … Read more

Compare a string using sh shell

You should use the = operator for string comparison: Sourcesystem=”ABC” if [ “$Sourcesystem” = “XYZ” ]; then echo “Sourcesystem Matched” else echo “Sourcesystem is NOT Matched $Sourcesystem” fi; man test says that you use -z to match for empty strings.

How can I split a shell command over multiple lines when using an IF statement?

The line-continuation will fail if you have whitespace (spaces or tab characters¹) after the backslash and before the newline. With no such whitespace, your example works fine for me: $ cat test.sh if ! fab –fabfile=.deploy/fabfile.py \ –forward-agent \ –disable-known-hosts deploy:$target; then echo failed else echo succeeded fi $ alias fab=true; . ./test.sh succeeded $ … Read more