Slightly tweaking your script.
#!/bin/bash
Res=$(head -n 1 "$1")
tab=$(head -n 1 "$2")
[[ $Res == $tab ]] && echo The same
Notes
- "dot" is not a valid identifier (i.e. variable name) character: valid is letters, numbers and underscore, and the first character cannot be a number.
- if you're doing
head -1
, there's no need to pipe that intotail -1
- I think
[[
is more readable thantest
, primarily because[[
forces you to have]]
- parentheses launch a subshell which is overkill for an echo statement.
- the exit will only exit the subshell not your program
- if you have multiple statements, use
if ...; then ...; fi
-- it's more readable.