# One-off shell script execution in BBEdit

DevFeed: [One-off shell script execution in BBEdit](<https://devfeed.tech/articles/one-off-shell-script-execution-in-bbedit-35131.md>)

Original publisher: [Read original article](<http://www.practicallyefficient.com/2017/06/14/shell-scripts-in-bbedit.html>)

Author: Eddie Smith

Published: 2017-06-14T00:00:00Z

Content type: tutorial

Language: en

Sources: [Eddie Smith](<https://devfeed.tech/sources/eddie-smith.md>)

Topics: [Scripting, bash](<https://devfeed.tech/topics/scripting-bash.md>), [Sublime Text](<https://devfeed.tech/topics/sublime-text.md>), [Terminal](<https://devfeed.tech/topics/terminal.md>), [file](<https://devfeed.tech/topics/file.md>), [LaTeX](<https://devfeed.tech/topics/latex.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [chmod](<https://devfeed.tech/tags/chmod.md>), [command](<https://devfeed.tech/tags/command.md>), [commands](<https://devfeed.tech/tags/commands.md>), [copy](<https://devfeed.tech/tags/copy.md>), [editor](<https://devfeed.tech/tags/editor.md>), [execution](<https://devfeed.tech/tags/execution.md>), [file](<https://devfeed.tech/tags/file.md>), [files](<https://devfeed.tech/tags/files.md>), [mac](<https://devfeed.tech/tags/mac.md>), [multiple](<https://devfeed.tech/tags/multiple.md>), [script](<https://devfeed.tech/tags/script.md>), [shell](<https://devfeed.tech/tags/shell.md>), [shell-script](<https://devfeed.tech/tags/shell-script.md>)

## AI overview

The article describes a workflow for creating one-off Bash scripts in Sublime Text to copy selected files, then running the unsaved commands immediately in BBEdit.

## Source excerpt

I've been meaning to talk more about my "Sublime Text and BBEdit" workflow, and this is a powerful (if mundane) example. I don't write a ton of scripts on my Mac and generally don't spend much time in Terminal. But when I need a script, I really need a script. My work is very file-heavy. I juggle large numbers of .tex (LaTeX) files across several large folder structures. Every so often I need to copy a subset of files within one folder to another folder so that I can do things to them. In most cases, I have a list of the files in a plain text .tex file, and I just need to do some file operations on them. Selecting them individually in Finder is tedious and error-prone, so the solution is usually a simple bash script with a bunch of cp commands. The main friction with bash scripting for folks like me that don't live in Terminal is that you have to create a .sh script and then web search for now to make it executable (because I can never remember the chmod command). Creating the shell commands is straightforward, especially in Sublime Text. After adding the necessary #!/bin/bash line with TextExpander and defining the "to" and "from" file paths as variables, the magic of Sublime Text's multiple cursors makes it easy to put cp commands and the folder path variables around each file to be copied. Sublime Text multiple cursors in action Since Sublime Text won't execute these commands in an unsaved file that hasn't been given proper execute permissions, I simply copy this text into an untitled, unsaved BBEdit window and hit ⌘R. BBEdit has the extremely useful ability to immediately recognize the syntax and execute it right there on the spot. I realize this post is a weird way to promote BBEdit, which is a powerful text editor that, in this case, I'm not even using as an editor. Hopefully I'll find some time to talk more about other ways I'm using it with Sublime Text.