Noob needs help with scripts


Recommended Posts

Hi!

 

I am trying to simplify my work at the university and this can only be achieved by using some scripts I have created. So the problem is that I am a bit, how to say this, uneducated in this topic :rofl: .

 

What I would like to do is a script that does its job in a folder where I have put it. There is a parent structure e.g. /data/work/patientname/other_folders_that_the_program_creates_by_itself

 

The problem is that I have to write a script that is universal for this kind of folder structure. This means it can recognize where it is.

Like this:

 

/data/work/jesse_james/script.sh works with every files and subfolders in the jessie_james directory the same way like it is in /data/work/lionel_richie/script.sh without rewriting the parent structure.

 

The script triggers for example fslview that opens /data/work/jessie_james/highres_brain.nii.gz or /data/work/james_earl_jones/highres_brain.nii.gz according to which folder was the script started from. So it must not care for the first few folders in which it is in. /data/work/patientname/ has to be ignored or known.

 

How can I do this :woot:

 

Thank you for your help guys!

Link to comment
Share on other sites

Why not have one copy of the script in a known location (or on the system path), and when you run the script, have it automatically look at what the current working directory is, and use that for the rest of the operations?

Rough example:

#!/bin/bash

BASE_DIR=`pwd`

fslview $BASE_DIR/hires_brain.nii.gz

Store that in say /data/work/script.sh, and then cd to /data/work/jessie_james, then call ../script.sh

  • Like 2
Link to comment
Share on other sites

It has a simple reason why I did not this in the first place. And it is because I did not know I could do this :D I will try it. Thank you :D

Link to comment
Share on other sites

This topic is now closed to further replies.