0

I have a basic script that runs inside another script. I call mass_split.sh which then invokes split_file.sh. The splite_file.sh takes two arguments -s file_name.txt and -c 1 (how many slices to cut the file). However I trying to run a loop to find all text file names in directory ./ and then input the results to the cut_file.sh . I am getting no results back and then text files are not being split.

mass_split.sh

#!/bin/bash
for f in ./*.txt
do
sudo bash split_file.sh -s echo "file '$f'"; -c 10
done
10
  • Your use of sudo bash [script] ... indicates to me that you're not 1) setting the script executable or 2) using a magic shebang, otherwise it would read sudo ./split_file.sh .... (applies to split_file.sh, not mass_split.sh which we can see the shebang for) Commented Oct 8, 2014 at 2:37
  • 1
    You don't need the echo part. I'd suggest in the for loop the following instead of what you have: sudo bash split_file.sh -s $f -c 10 Commented Oct 8, 2014 at 2:47
  • the -c10 part after the ; will return: command not found. Drop the ; Also, when I exclude the bash split_file.sh ... (because i don't have that command nor the code) it lists the files perfectly. You might as well show the code for split_file.sh. It might help. Commented Oct 8, 2014 at 2:52
  • @thom it takes echo as the file name and not the value passed in Commented Oct 8, 2014 at 2:57
  • 1
    Thanks @Code_Ed_Student. I was late in reading your comment. A side note, if you'll write shell scripts more, I think you need to study it further as your question indicates lack of 'shell proficiency' :) Best wishes! Commented Oct 8, 2014 at 14:51

1 Answer 1

1

Maybe this has something to do with that errant semicolon after the string literal, which is almost certainly not doing what you want (unless you have another executable that you're intentionally running called -c).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.