---
slug: "bash-remove-trailing-slash"
title: "Remove Trailing Slash from Variable in Bash"
description: "Strip a trailing slash from a Bash variable with the parameter expansion `${var%/}`. Useful for normalizing paths from arguments or env vars."
url: "https://www.ytyng.com/en/blog/bash-remove-trailing-slash"
publish_date: "2015-05-13T01:35:52Z"
created: "2015-05-13T01:35:52Z"
updated: "2026-05-11T12:57:42.147Z"
categories: ["Linux"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/515e50f51f5f48cb8244c3e1564536b6.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# Remove Trailing Slash from Variable in Bash

<div class="document">


<p>Removing the trailing / from $1</p>
<pre class="literal-block">${1%/}
</pre>
</div>
