I'm learning shell scripting! For the same I've tried downloading the TCGA genome data using curl on ubuntu (Ubuntu 16.04.3 LTS) terminal.
sh. content
#!/bin/sh
echo /0c8a6022-b770-4a83-bac3-b1526a16c89a/;
token=$(<gdc-user-token.2018-06-26T14_36_13.548Z.txt)
export ec=18; while [ $ec -ne 0 ]; do curl -C - -H "X-Auth-Token: $token" 'https://api.gdc.cancer.gov/slicing/view/0c8a6022-b770-4a83-bac3-b1526a16c89a?region=chr9:131270948-131270948' > STAD/chr9:131270948-131270948_C440.TCGA-BR-6453-01A-11D-1800-08.3_gdc_realn.bam; export ec=$?;done
If I run the sh script, downloaded file is empty, without any error message.
But if the run the command directly then it is working fine.
I will appreciate if anyone let me know the mistake I am doing in the script.
You are probably not running the script in bash.
/bin/sh
is a symlink to/bin/dash
, the default non-interactive shell in Ubuntu (since version 6.10).dash
doesn't support the shortcut command$(<filename)
, so yourtoken
variable is empty.To execute the script with bash, change the shebang line to
#!/bin/bash
or explicitly invokebash script.sh
.Generally, if you want/need to use a specific shell, you should explicitly specify it in the shebang line. If you want your script to be portable, you can specify
#!/bin/sh
, but then you have to make sure your script is POSIX-compliant. For example, the POSIX-compliant equivalent of$(<filename)
would be$(cat filename)
.