This question already has answers here:
How do I pass on script arguments that contain quotes/spaces?
(2 answers)
Bash script to cd to directory with spaces in pathname
(14 answers)
Closed 24 days ago.
I have a script that appends the date and time to all files in a folder. I use the script like this...
bash append_date.sh /home/user/Documents/Podcasts/
and that will append the date to all files in the /home/user/Documents/Podcasts/ folder
Problem is that if there is a whitespace in the directory tree it fails to do anything. ie
bash append_date.sh /home/user/Documents/My Stuff/
I have tried passing the following, but that does not work
bash append_date.sh /home/user/Documents/My\ Stuff/
How do I get this script to play nice with whitespaces?
Many thanks for any help.
Related
This question already has answers here:
Unix: How to delete files listed in a file
(13 answers)
Shell command/script to delete files whose names are in a text file
(7 answers)
Closed 2 years ago.
I have a file with several paths to other files.
/root/Desktop/test1/test2/f1
/root/Desktop/test1/test2/f2
I need to execute a command from the terminal to delete f1 and f2 by importing their paths from that file.
Something like "rm code"
code = line 1 of the file text
Is there a way to do so ?
rm root/Desktop/test1/test2/f*
should do if I understood your question.
This question already has answers here:
How do I parse command line arguments in Bash?
(40 answers)
How to get exact command line string from shell?
(2 answers)
Closed 3 years ago.
Suppose my script.sh could take a number of options and arguments. What is the best way to find out what the script was invoked with (form inside the script)?
For eg., someone called it with script.sh --foo_option bar_arg
Is there a way to echo that exact command they typed from inside the script?
I've tried echo !! which does not work inside a script.
This question already has answers here:
Tilde in path doesn't expand to home directory
(5 answers)
Closed 4 years ago.
I'm using variables in bash script to hold folder names (to iterate over multiple folders).
I'd like to copy files from one to another, the files exist in source directory. Folders and filenames contain spaces, so I must use double quote.
For instance:
#!/bin/bash
inpath="~/foo bar/"
outpath="~/temp basket/
cp "$inpath*" "$outpath"
The copy fails as: '~/foo bar/*' No such file or directory
Is there any consistent way to do that?
Only quote the parts you don't want expanded or split:
inpath=~/'foo bar'
outpath=~/'temp basket'
cp -- "$inpath/"* "$outpath"
This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
Run bash commands from txt file
(4 answers)
Closed 5 years ago.
I have a script shell that is reading from a file. This is the command line text that i would like to run under the bin folder of neo4j
bin/neo4j-import --into /home/micmal/neo4j-community-3.0.1/data/databases/graph_test.db --id-type string --nodes:
I would like to use a script shell to get that command and go to the folder of neo4j and paste it so it runs.
my shell looks like :
#!/bin/bash
batch_import_value= `cat _batchfile.txt`
cd /home/neo4j-community-3.0.1/
echo $batch_import_value`
it doesn't seem work
Any idea?
This question already has answers here:
How can I remove the extension of a filename in a shell script?
(15 answers)
Closed 5 years ago.
I have hundreds files need to loop through for an analysis using a bash script. One step I need to do is to split a long string and cat it as an output name. For example, suppose I have one string such like:
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final.bam
What I wanted is to rename it as two output file names such as:
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R1.fastq
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R2.fastq
The only changes are removing .bam from the original and cat _R1.fastq and _R2_fastq. Does somebody know how to realize it using bash commands?
somefile=blahblahblah.final.bam
foo "$somefile" "${somefile%.*}_R1.fastq" "${somefile%.*}_R2.fastq"