[ubuntu-uk] Bash and Path checks
Are you doing this to avoid the mkdir if the directory you are creating already exists? If so, then the is an option -p which means it is not an error if the directory already exists. It also creates parent directories as needed, so: mkdir -p $newPath/Sound/MP3 mkdir -o $newpath/Sound/wav will do what you want without the need to test. (BTW, it's forward slashes / in Linux, not backslahes!) Of course, I may have misunderstood what you are trying to achieve. Regards, Tony. Thanx I will try the -p option. As I understand it the \ is to pipe whatever onto what is infront of the \ so it reads Get the Variable and Pipe the following onto it ... You have understood my question... Thanx -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Bash and Path checks
pipe is | not \ \ is the way you make a character literal. In other words you remove it from the parsing and have it interpreted as the character it is. Like I'm going slightly \mad\... ;-) Best, Sean -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Bash and Path checks
Cornelius, Cornelius Mostert wrote: Are you doing this to avoid the mkdir if the directory you are creating already exists? If so, then the is an option -p which means it is not an error if the directory already exists. It also creates parent directories as needed, so: mkdir -p $newPath/Sound/MP3 mkdir -o $newpath/Sound/wav Oops! That last line should read: mkdir -p $newPath/Sound/wav will do what you want without the need to test. (BTW, it's forward slashes / in Linux, not backslahes!) Of course, I may have misunderstood what you are trying to achieve. Regards, Tony. Thanx I will try the -p option. As I understand it the \ is to pipe whatever onto what is infront of the \ so it reads Get the Variable and Pipe the following onto it ... You were using it as a separator in a path to separate the various directory names. In Linux/Unix that should be a forward slash (/). Windows uses the backslash (\) for such purposes. As others have pointed out, pipes are something else. You have understood my question... Oh good! I was worried I had missed something! Regards, Tony. -- Tony Arnold,Tel: +44 (0) 161 275 6093 Head of IT Security,Fax: +44 (0) 870 136 1004 University of Manchester, Mob: +44 (0) 773 330 0039 Manchester M13 9PL. Email: tony.arn...@manchester.ac.uk -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
[ubuntu-uk] Bash and Path checks
Thanx but I am familiar with / in Linux and \ in windows... i saw a script use \ as i did and naturally I assumes (incorrectly though) that it is also | (pipe) but backward pipe like , come to think of it the path the person wanted to append to the variable a path that contained a space in it so that is why he used the \ to make the script use the space in the path and not think that it is a second parameter... UMmmm Note to self and others try not to use spaces in file paths :-) but then again you guys know that ... will do what you want without the need to test. (BTW, it's forward slashes / in Linux, not backslahes!) Of course, I may have misunderstood what you are trying to achieve. Regards, Tony. Thanx I will try the -p option. As I understand it the \ is to pipe whatever onto what is infront of the \ so it reads Get the Variable and Pipe the following onto it ... You were using it as a separator in a path to separate the various directory names. In Linux/Unix that should be a forward slash (/). Windows uses the backslash (\) for such purposes. As others have pointed out, pipes are something else. You have understood my question... Oh good! I was worried I had missed something! -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Bash and Path checks
Cornelius Mostert wrote: Thanx but I am familiar with / in Linux and \ in windows... i saw a script use \ as i did and naturally I assumes (incorrectly though) that it is also | (pipe) but backward pipe like , come to think of it the path the person wanted to append to the variable a path that contained a space in it so that is why he used the \ to make the script use the space in the path and not think that it is a second parameter... UMmmm Note to self and others try not to use spaces in file paths :-) but then again you guys know that ... Hello, Cornelius. You do sometimes see '\' after a pipe, when it is used to escape newlines, in order to make shell scripts more readable. For example the one-line pipeline: command1 with lots of arguments | command2 with many more arguments Can be written on two lines as: command1 with lots of arguments |\ command2 with many more arguments This pipeline can also be written as: command1 with lots of arguments \ | command2 with many more arguments I prefer the second style, which makes it more obvious what the scope of the pipeline is. You can put quotes around paths with spaces in them. Bye, Tony. -- Dr. A.J.Travis, University of Aberdeen, Rowett Institute of Nutrition and Health, Greenburn Road, Bucksburn, Aberdeen AB21 9SB, Scotland, UK tel +44(0)1224 712751, fax +44(0)1224 716687, http://www.rowett.ac.uk mailto:a.tra...@abdn.ac.uk, http://bioinformatics.rri.sari.ac.uk/~ajt -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
[ubuntu-uk] Bash and Path checks
Hallo I wrote my first Bash script! However I am struggling to find a way to test if 2 paths are the same: 1. I use a for loop to run through a set of folders in a path (lets say /home/myFiles/) 2. Now Test if the File Extension is = mpg 2.1. If true then I would like to know if the path of the previous mpg file is the same as this mpg file 2.1.1. If != then I would like to create a few dirs in this new path So script looks like: for file in 4StartPath do fileExt = (get the file extention from 4file) if [ $fileExt = 'mpg' ] then newPath = (get File Path form $file) if [ $newPath != $oldPath ] then mkdir $newPath\Sound mkdir $newPath\Sound\MP3 mkdir $newPath\Sound\wav fi ffmpeg ding dong grab the MP3 and the Wav mv mp3 and wav file to directories created Obviously this is not the Exact script but i am struggling to do the if [ $newPath != $oldPath ] bit as I am new to bash scripts a code snippet would be nice and as I would like to know what the code does could you explaine it to me as well :-) Pretty please -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Bash and Path checks
2009/4/17 Cornelius Mostert corneliusmost...@googlemail.com: Hallo I wrote my first Bash script! However I am struggling to find a way to test if 2 paths are the same: 1. I use a for loop to run through a set of folders in a path (lets say /home/myFiles/) 2. Now Test if the File Extension is = mpg 2.1. If true then I would like to know if the path of the previous mpg file is the same as this mpg file 2.1.1. If != then I would like to create a few dirs in this new path So script looks like: for file in 4StartPath do fileExt = (get the file extention from 4file) if [ $fileExt = 'mpg' ] then newPath = (get File Path form $file) if [ $newPath != $oldPath ] then mkdir $newPath\Sound mkdir $newPath\Sound\MP3 mkdir $newPath\Sound\wav fi ffmpeg ding dong grab the MP3 and the Wav mv mp3 and wav file to directories created Obviously this is not the Exact script but i am struggling to do the if [ $newPath != $oldPath ] bit as I am new to bash scripts a code snippet would be nice and as I would like to know what the code does could you explaine it to me as well :-) Pretty please -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/ Does it have to work with symlinks and relative paths? If so, the only way (as I understand it) is to cd into the directory and use the pwd command to get the directory name. If not, you could try putting double-quotes around the variables in the if test, i.e. if [ $newPath != $oldPath ] This does a string comparison. This is all untested. I'm OK at bash scripting, but not an expert by any measure. Cofion/Regards, Neil. -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] Bash and Path checks
Cornelius, Cornelius Mostert wrote: Hallo I wrote my first Bash script! However I am struggling to find a way to test if 2 paths are the same: 1. I use a for loop to run through a set of folders in a path (lets say /home/myFiles/) 2. Now Test if the File Extension is = mpg 2.1. If true then I would like to know if the path of the previous mpg file is the same as this mpg file 2.1.1. If != then I would like to create a few dirs in this new path So script looks like: for file in 4StartPath do fileExt = (get the file extention from 4file) if [ $fileExt = 'mpg' ] then newPath = (get File Path form $file) if [ $newPath != $oldPath ] then mkdir $newPath\Sound mkdir $newPath\Sound\MP3 mkdir $newPath\Sound\wav fi ffmpeg ding dong grab the MP3 and the Wav mv mp3 and wav file to directories created Obviously this is not the Exact script but i am struggling to do the if [ $newPath != $oldPath ] bit Are you doing this to avoid the mkdir if the directory you are creating already exists? If so, then the is an option -p which means it is not an error if the directory already exists. It also creates parent directories as needed, so: mkdir -p $newPath/Sound/MP3 mkdir -o $newpath/Sound/wav will do what you want without the need to test. (BTW, it's forward slashes / in Linux, not backslahes!) Of course, I may have misunderstood what you are trying to achieve. Regards, Tony. -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/