# To skip operations in UNIX shell

**URL:** <https://community.unix.com/t/to-skip-operations-in-unix-shell/342308>\
**Category:** Shell Programming and Scripting\
**Created:** [May 2, 2014, 2:39am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308 "2014-05-02T02:39:17Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohit\_shinez](https://community.unix.com/letter_avatar/rohit_shinez/32/5_5575768a8748004e209b776fc1b2916d.png) [@rohit\_shinez](https://community.unix.com/u/rohit_shinez)\
**Post date:** [May 2, 2014, 2:39am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/1 "2014-05-02T02:39:17Z")

</div>

hi i am having a acript for which i need to skip the execution of some lines and to continue with remaining lines for eg

```nohighlight
script.sh
rm text
for i in *
do 
.
.
.
.
.
if [x = y]
then 
rm
 

```

i want to skip the execution of the lines and to start with

```nohighlight
if [x = y]
then 
rm

```

---

<div class="post-metadata">

**Author:** ![chacko193](https://community.unix.com/letter_avatar/chacko193/32/5_5575768a8748004e209b776fc1b2916d.png) [@chacko193](https://community.unix.com/u/chacko193)\
**Post date:** [May 2, 2014, 2:58am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/2 "2014-05-02T02:58:31Z")

</div>

Put them in a condition thats never true.

```nohighlight
if [1 == 0];then
script.sh
 rm text
 for i in * 
do
.
.
.
.
 .
done
fi
if [x = y] 
then
 rm

```

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 2, 2014, 3:05am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/3 "2014-05-02T03:05:29Z")

</div>

Put comment signs in front of the lines:

```nohighlight
# rm text
# for i in *
# do 
# .
# .
# .
# .
# done
# .
if [x = y]
then 
rm

```

---

<div class="post-metadata">

**Author:** ![rohit\_shinez](https://community.unix.com/letter_avatar/rohit_shinez/32/5_5575768a8748004e209b776fc1b2916d.png) [@rohit\_shinez](https://community.unix.com/u/rohit_shinez)\
**Post date:** [May 2, 2014, 3:24am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/4 "2014-05-02T03:24:14Z")

</div>

hi

i dont wanted to comment each line since the script is very huge

---

<div class="post-metadata">

**Author:** ![chacko193](https://community.unix.com/letter_avatar/chacko193/32/5_5575768a8748004e209b776fc1b2916d.png) [@chacko193](https://community.unix.com/u/chacko193)\
**Post date:** [May 2, 2014, 3:27am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/5 "2014-05-02T03:27:27Z")

</div>

If you dont want to comment it out, then you can use the "if" condition.

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 2, 2014, 3:29am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/6 "2014-05-02T03:29:52Z")

</div>

Well, if you use `vi` you can use:

```plaintext
:1,/if \[x = y\]/s/^/# /

```

And then delete the last comment...

--

> [@chacko193](#):
>
> Put them in a condition thats never true.
> 
> ```plaintext
> if [1 == 0];then
> [..]
> 
> ```

The correct syntax is

```plaintext
if [1 = 0]; then

```

But you could also use:

```plaintext
if []; then

```

or

```plaintext
if false; then

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [May 2, 2014, 6:39am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/7 "2014-05-02T06:39:32Z")

</div>

If your shell allows for here documents, you could try

```nohighlight
script.sh
<<EOF
rm text
for i in *
do
.
.
.
.
.
EOF
if [x = y] then rm

```

Make sure that the token (here:EOF) does not occur anywhere in the portion to be skipped.

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 2, 2014, 7:18am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/8 "2014-05-02T07:18:20Z")

</div>

If you use a here-document construct for that, also make sure that there quotes around the first EOF ( `<<"EOF"` ), otherwise parameter expansion, command substitution, and arithmetic expansion will still occur within that block.

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [May 2, 2014, 7:30am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/9 "2014-05-02T07:30:30Z")

</div>

True, Scrutinizer. But that wouldn't hurt, would it? Except for some waste of CPU- ressourses?

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 2, 2014, 7:48am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/10 "2014-05-02T07:48:37Z")

</div>

> [@rudic](#):
>
> True, Scrutinizer. But that wouldn't hurt, would it? Except for some waste of CPU- ressourses?

Well command substitution might hurt, depending on what is being done inside. Anyway I would not want to leave that to chance..

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [May 2, 2014, 11:25am UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/11 "2014-05-02T11:25:02Z")

</div>

> [@rudic](#):
>
> True, Scrutinizer. But that wouldn't hurt, would it? Except for some waste of CPU- ressourses?

Parameter substitution includes $() and backticks. It could well end up doing something...

---

<div class="post-metadata">

**Author:** ![wisecracker](https://community.unix.com/user_avatar/community.unix.com/wisecracker/32/2800_2.png) [@wisecracker](https://community.unix.com/u/wisecracker)\
**Post date:** [May 2, 2014, 12:51pm UTC](https://community.unix.com/t/to-skip-operations-in-unix-shell/342308/12 "2014-05-02T12:51:47Z")

</div>

Not sure if this might be an idea...

Create a function from the \_\_unwanted\_\_ code:-

```nohighlight
unused()
{
# All your temporary code here...
}

```

EDIT:  
As a bonus if you need it you can call it...
