0

I have part of shell script as below..

spark_data=spark-shell << EOF spark.sql(query) EOF

i need the exit status of the spark.sql query.. Can someone help on this..

Awaiting your reply Thanks

1 Answers1

1

Since the assignment is part of another command, the exit status of the assignment is the exit status of the command substitution.

$ foo=$(cat <<EOF
> hi
> there
> EOF
> exit 9)
$ echo $?
9
$ echo "$foo"
hi
there
chepner
  • 497,756
  • 71
  • 530
  • 681
  • The above strategy will not work with herein EOF. Can anyone try and answer oks – RAVINDAR MEDA Sep 14 '20 at 04:01
  • Sure it does; you just can't put it all on one line (which is true no matter where you use a here document). – chepner Sep 14 '20 at 13:09
  • In the above eg you used exit 9 after EOF..But in my case I have Scala language commands in the place of 'Hi there '..what i need is spark-shell exit status..in you example it's cat command exit status – RAVINDAR MEDA Sep 16 '20 at 18:08
  • I need the exact exit status of those Scala commands in spark-shell...like exit 0 so that I need to know the success or failure of those commands inside EOF.........HERE spark-shell is like your cat Scala commands are like hi there..I want exit status of spark-shell as your cat in the eg.. – RAVINDAR MEDA Sep 16 '20 at 18:16
  • I already check with your strategy but it dint work for me.. – RAVINDAR MEDA Sep 16 '20 at 18:16
  • As cat command is internal to Unix it gave the exit status correctly in your case I think – RAVINDAR MEDA Sep 16 '20 at 18:28
  • `cat` is no more internal than `spark-shell`. It has nothing to do with the shell. It's only there to provide output to be assigned to `foo`. The exit status of the command substitution is 9, and that's the exit status of the assignment itself. The Scala commands don't *have* an exit status, at least not in the sense that the shell can access. – chepner Sep 16 '20 at 18:32
  • So how can we get the exit status of spark-shell success or failure? I tried like below by giving va x instead of val x but dint work..spark-shell < – RAVINDAR MEDA Sep 17 '20 at 17:23