Mihkel L.
Mihkel L.

Reputation: 1573

Escape if statement in bash

I have a line in bash:

if [ -e /home/somefile.xml ]; then
 mv /home/somefile.xml /home/folder.fi/somefile.xml
fi

now my editor is coloring folder.fi's fi part as code. How can I escape it and does it really think it's code?

Upvotes: 0

Views: 567

Answers (3)

John Kugelman
John Kugelman

Reputation: 361849

Your editor's syntax highlighting is incorrect. It is safe to ignore it. The fi in the file name does not end the if block.

Upvotes: 2

Kewin Dousse
Kewin Dousse

Reputation: 4027

The .fi is not the problem, bash doesn't interpret the dot in the middle of a path. Instead, you're missing spaces on the first line

if [ -e /home/somefile.xml ]; then
  mv /home/somefile.xml /home/folder.fi/somefile.xml
fi

Also I'd recommand to put your file paths in double quotes like this :

mv "/home/somefile.xml" "/home/folder.fi/somefile.xml"

The editor should interpret it correctly with quotes, even if your first code is correct.

Upvotes: 1

DRC
DRC

Reputation: 5048

You need spaces after and before those [

if [ -e /home/somefile.xml ]; then
 mv /home/somefile.xml /home/folder.fi/somefile.xml
fi

Upvotes: 1

Related Questions